コード例 #1
0
ファイル: SRPGChoiceView.java プロジェクト: keppelcao/LGame
 /**
  * 设定选择器的基本构成(背景图,文字信息,信息连接顺序,字体,坐标)
  *
  * @param image
  * @param messages
  * @param joint
  * @param font
  * @param x
  * @param y
  */
 public void set(LTexture image, String[][] messages, int[] joint, LFont font, int x, int y) {
   super.exist = true;
   super.cancelflag = false;
   StringBuffer sbr = new StringBuffer(100);
   for (int j = 0; j < messages.length; j++) {
     for (int i = 0; i < messages[j].length; i++) {
       sbr.append(messages[j][i]);
     }
   }
   LSTRDictionary.bind(font, sbr.toString());
   this.dialogImage = image;
   this.defFont = font;
   this.choice = messages;
   this.joint = joint;
   this.posX = x;
   this.posY = y;
   this.tab = 10;
   this.mesList = new int[messages[0].length];
   for (int i = 0; i < mesList.length; i++) {
     mesList[i] = 0;
   }
   for (int i = 0; i < messages.length; i++) {
     for (int j = 0; j < messages[i].length; j++) {
       int width = defFont.stringWidth(messages[i][j]);
       if (mesList[j] < width) {
         mesList[j] = width;
       }
     }
   }
   // 单独一行高度
   this.height = defFont.getHeight();
   // 获得默认的上下文间隔大小
   this.space = height + defFont.getSize() / 2;
   this.width = getWidthTotal(mesList, tab);
   // 颜色集合(用以改变指定行选项颜色)
   this.colors = new LColor[messages.length];
   for (int i = 0; i < colors.length; i++) {
     colors[i] = null;
   }
   this.view = 0;
   this.maxSize = choice.length;
   this.select = 0;
   this.visible = true;
 }
コード例 #2
0
ファイル: LTextList.java プロジェクト: hyg864454022/LGame
  public void draw(GLEx g, int x, int y, float mouseX, float mouseY) {
    if (this.max > 0) {

      LFont oldFont = g.getFont();
      int oldColor = g.color();

      g.setFont(this.font);
      int fontSize = font.getSize();

      // 如果没有设置背景,则绘制
      if (bgTexture == null) {
        g.setColor(this.listColor);
        g.fillRect(x, y, getWidth(), getHeight());
        g.setColor(255, 255, 255);
        g.drawRect(x, y, getWidth(), getHeight());
      } else {
        g.draw(bgTexture, x, y, getWidth(), getHeight());
      }

      this.drawNum = ((getHeight() - 10) / fontSize);
      this.loop = 0;
      this.selectList = -1;

      for (int i = this.scrollList; i < this.drawNum + this.scrollList; i++) {
        if (i >= this.num) break;
        this.drawX = (x + 5);
        this.drawY = (y + 5 + this.loop * fontSize);

        if (!this.scrollBarDrag) {
          if ((mouseY > this.drawY)
              && (mouseY <= this.drawY + fontSize)
              && (mouseX > this.drawX)
              && (mouseX < this.drawX + getWidth())) {
            this.selectList = i;
          }
        }

        // 计算是否选中当前行
        if (!this.lengthCheck[i]) {
          this.lengthCheck[i] = true;
          if (this.name[i] != null) {
            while (font.stringWidth(this.name[i]) > getWidth()) {
              this.name[i] = this.name[i].substring(0, this.name[i].length() - 1);
            }
          }
        }

        if ((this.selectList == i) || ((this.useHold) && (this.hold == i))) {
          if ((this.useHold) && (this.hold == i)) {
            g.setColor(255, 255, 0);
            g.fillRect(x + 1, this.drawY, getWidth() - 1, fontSize);
            g.setColor(LColor.black);
            drawString(g, this.name[i], this.drawX, this.drawY);
            this.hold = -1;
          }
          // 选中指定列时
          if (this.selectList == i) {
            if (choiceTexture == null) {
              g.setColor(this.choiceStringBoxColor);
              g.fillRect(x + 1, this.drawY, getWidth() - 2, fontSize + 2);
            } else {
              g.draw(this.choiceTexture, x + 2, this.drawY, getWidth() - 2, fontSize + 2);
            }
            g.setColor(this.choiceStringColor);
            drawString(g, this.name[i], this.drawX, this.drawY);
          }
        } else {
          g.setColor(this.color[i]);
          drawString(g, this.name[i], this.drawX, this.drawY);
        }

        this.loop += 1;
      }

      this.scrollBarX = (x + getWidth() + 1);

      this.scrollBarHeight_max = (getHeight() - this.scrollButtonHeight * 2);

      if ((this.drawNum < this.num) && (this.drawNum > 0)) {
        this.scrollBarHeight = (this.scrollBarHeight_max / this.num / this.drawNum);
        this.scrollBarHeight = (this.scrollBarHeight_max * this.drawNum / this.num);
        if (this.scrollBarHeight < 8) this.scrollBarHeight = 8;

        this.scrollBarY = (y + this.scrollButtonHeight + 1);
        this.scrollBarY +=
            (this.scrollBarHeight_max - this.scrollBarHeight)
                * this.scrollList
                / (this.num - this.drawNum);
      } else {
        this.scrollBarHeight = this.scrollBarHeight_max;
        this.scrollBarY = (y + this.scrollButtonHeight + 1);
      }

      if (this.scrollBarDrag) {
        if (mouseY < this.scrollBarY + this.scrollBarHeight / 3) {
          for (int i = 0; i < 5; i++) {
            if (this.scrollList <= 0) break;
            this.scrollList -= 1;
          }
        }

        if (mouseY > this.scrollBarY + this.scrollBarHeight * 2 / 3) {
          for (int i = 0; i < 5; i++) {
            if (this.scrollList >= this.num - this.drawNum) break;
            this.scrollList += 1;
          }
        }
      }

      if (SysTouch.isDrag()) {
        if ((mouseX > this.scrollBarX)
            && (mouseX <= this.scrollBarX + this.scrollButtonWidth)
            && (mouseY > y + this.scrollButtonHeight)
            && (mouseY < y + getHeight() - this.scrollButtonHeight)) {
          this.scrollBarDrag = true;
        }
      } else {
        this.scrollBarDrag = false;
      }

      if (scrollTexture == null) {
        if (this.scrollBarDrag) {
          g.setColor(0, 255, 255);
        } else {
          g.setColor(255, 255, 255);
        }
        g.fillRect(this.scrollBarX, this.scrollBarY, this.scrollButtonWidth, this.scrollBarHeight);
      } else {
        g.draw(
            this.scrollTexture,
            this.scrollBarX,
            this.scrollBarY,
            this.scrollButtonWidth,
            this.scrollBarHeight);
      }

      this.scrollButtonX = (x + getWidth());
      this.scrollButtonY = y;

      if (scrollFlagATexture == null) {
        if (this.scrollUpButtonON) {
          g.setColor(LColor.gray);
        } else {
          g.setColor(LColor.black);
        }
        g.fillRect(
            this.scrollButtonX + 1,
            this.scrollButtonY + 1,
            this.scrollButtonWidth,
            this.scrollButtonHeight);
        g.setColor(255, 255, 255);
        this.px[0] = (this.scrollButtonX + 1 + this.scrollButtonWidth / 6);
        this.px[1] = (this.scrollButtonX + 1 + this.scrollButtonWidth / 2);
        this.px[2] = (this.scrollButtonX + 1 + this.scrollButtonWidth * 5 / 6);
        this.py[0] = (this.scrollButtonY + 1 + this.scrollButtonHeight * 5 / 6);
        this.py[1] = (this.scrollButtonY + 1 + this.scrollButtonHeight / 6);
        this.py[2] = (this.scrollButtonY + 1 + this.scrollButtonHeight * 5 / 6);
        g.fillPolygon(this.px, this.py, 3);
      } else {
        g.draw(
            this.scrollFlagATexture,
            this.scrollButtonX + 1,
            this.scrollButtonY + 1,
            this.scrollButtonWidth - 1,
            this.scrollButtonHeight - 1);
      }

      this.scrollUpButtonON = false;
      if ((!this.scrollBarDrag)
          && isFocusable()
          && (mouseX > this.scrollButtonX)
          && (mouseX <= this.scrollButtonX + this.scrollButtonWidth)
          && (mouseY > this.scrollButtonY)
          && (mouseY < this.scrollButtonY + this.scrollButtonHeight)) {
        if (this.scrollList > 0) {
          this.scrollList -= 1;
        }
        this.scrollUpButtonON = true;
      }
      this.scrollButtonX = (x + getWidth());
      this.scrollButtonY = (y + getHeight() - this.scrollButtonHeight);
      this.scrollDownButtonON = false;
      if ((!this.scrollBarDrag)
          && isFocusable()
          && (mouseX > this.scrollButtonX)
          && (mouseX <= this.scrollButtonX + this.scrollButtonWidth)
          && (mouseY > this.scrollButtonY)
          && (mouseY < this.scrollButtonY + this.scrollButtonHeight)) {
        if (this.scrollList < this.num - this.drawNum) {
          this.scrollList += 1;
        }
        this.scrollDownButtonON = true;
      }
      if (scrollFlagBTexture == null) {
        if (this.scrollDownButtonON) {
          g.setColor(LColor.gray);
        } else {
          g.setColor(LColor.black);
        }
        g.fillRect(
            this.scrollButtonX + 1,
            this.scrollButtonY - 1,
            this.scrollButtonWidth,
            this.scrollButtonHeight);
        g.setColor(LColor.white);
        this.px[0] = (this.scrollButtonX + 1 + this.scrollButtonWidth / 6);
        this.px[1] = (this.scrollButtonX + 1 + this.scrollButtonWidth / 2);
        this.px[2] = (this.scrollButtonX + 1 + this.scrollButtonWidth * 5 / 6);
        this.py[0] = (this.scrollButtonY - 1 + this.scrollButtonHeight / 6);
        this.py[1] = (this.scrollButtonY - 1 + this.scrollButtonHeight * 5 / 6);
        this.py[2] = (this.scrollButtonY - 1 + this.scrollButtonHeight / 6);
        g.fillPolygon(this.px, this.py, 3);
      } else {
        g.draw(
            this.scrollFlagBTexture,
            this.scrollButtonX + 1,
            this.scrollButtonY + 1,
            this.scrollButtonWidth - 1,
            this.scrollButtonHeight - 1);
      }
      g.setFont(oldFont);
      g.setColor(oldColor);
    }
  }