Beispiel #1
0
 protected static final void serialize() {
   Iotil.writeFile(
       FurGuardiansGame.FILE_CFG,
       FurGuardiansGame.SEG_CFG
           + "|"
           + Chartil.unnull(defaultProfileName)
           + "|"
           + btnSize
           + "|"
           + zoomMag
           + "|"
           + musicEnabled
           + "|"
           + soundEnabled);
 }
Beispiel #2
0
 @Override
 public final boolean isMet(final Avatar avt) {
   return Chartil.startsWith(Player.getName(avt.clothing), "Royal ")
       && Avatar.HAT_CROWN.equals(Player.getName(avt.hat));
 }
public final class ControllerInput extends Input {
  private static final char[] UPPER = {
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
  };
  private static final char[] LOWER = {
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z'
  };
  private static final char[] LETTER = Chartil.concat(LOWER, UPPER);

  private char[] chars = UPPER;
  private int index;
  private int value;

  public ControllerInput(final Font font, final InputSubmitListener listener) {
    super(font, listener);
  }

  public ControllerInput(final MultiFont fonts, final InputSubmitListener listener) {
    super(fonts, listener);
  }

  private int getValue(final char c) {
    final int size = chars.length;
    for (int i = 0; i < size; i++) {
      if (c == chars[i]) {
        return i;
      }
    }
    return size;
  }

  private final void initChr(final int ind) {
    initChr(ind, chars.length);
  }

  private final void initChr(final int ind, final int val) {
    index = ind;
    value = val;
    label.setCursor(0, index);
  }

  @Override
  protected final void focus() {
    label.setCursorEnabled(true);
    initChr(buf.length());
    final Pangine engine = Pangine.getEngine();
    final Panput sub, adv, bak, up, down;
    if (ctrl == null) {
      final Panteraction in = engine.getInteraction();
      sub = in.KEY_ENTER;
      adv = in.KEY_SPACE;
      bak = in.KEY_ESCAPE;
      up = in.KEY_UP;
      down = in.KEY_DOWN;
    } else {
      sub = ctrl.getSubmit();
      adv = ctrl.get1();
      bak = ctrl.get2();
      up = ctrl.getUp();
      down = ctrl.getDown();
    }
    Panput.inactivate(sub, adv, bak, up, down);
    final ActionStartListener upListener =
        new ActionStartListener() {
          @Override
          public void onActionStart(final ActionStartEvent event) {
            if (value == chars.length) {
              value = 0;
              buf.append(' ');
            } else {
              value++;
            }
            if (value != chars.length) {
              buf.setCharAt(index, chars[value]);
            } else {
              buf.setLength(index);
            }
            change();
          }
        };
    final ActionStartListener downListener =
        new ActionStartListener() {
          @Override
          public void onActionStart(final ActionStartEvent event) {
            if (value == 0) {
              value = chars.length;
            } else {
              if (value == chars.length) {
                buf.append(' ');
              }
              value--;
            }
            if (value != chars.length) {
              buf.setCharAt(index, chars[value]);
            } else {
              buf.setLength(index);
            }
            change();
          }
        };
    final ActionStartListener advListener =
        new ActionStartListener() {
          @Override
          public void onActionStart(final ActionStartEvent event) {
            if (value != chars.length && (max <= 0 || buf.length() < max)) {
              initChr(index + 1);
            }
          }
        };
    final ActionStartListener bakListener =
        new ActionStartListener() {
          @Override
          public void onActionStart(final ActionStartEvent event) {
            if (index == 0) {
              return;
            } else if (value != chars.length) {
              buf.setLength(buf.length() - 1);
              change();
            }
            initChr(index - 1, getValue(buf.charAt(buf.length() - 1)));
          }
        };
    final ActionStartListener subListener =
        new ActionStartListener() {
          @Override
          public void onActionStart(final ActionStartEvent event) {
            close();
            sub.inactivate();
            submit();
          }
        };
    label.register(up, upListener);
    label.register(down, downListener);
    label.register(adv, advListener);
    label.register(bak, bakListener);
    label.register(sub, subListener);
  }

  public final void setChars(final char[] chars) {
    this.chars = chars;
  }

  public final void setUpper() {
    setChars(UPPER);
  }

  public final void setLower() {
    setChars(LOWER);
  }

  public final void setLetter() {
    setChars(LETTER);
  }
}