示例#1
0
  /**
   * @param chestContents What happens when this chest is opened
   * @param traps
   * @param mazeVariable The maze variable storing the state of this chest
   * @param preScript
   */
  public Chest(
      TileScript chestContents,
      PercentageTable<Trap> traps,
      String mazeVariable,
      String northTexture,
      String southTexture,
      String eastTexture,
      String westTexture,
      MazeScript preScript) {
    this.preScript = preScript;
    this.chestContents = chestContents;
    this.traps = traps;
    this.mazeVariable = mazeVariable;
    this.northTexture = northTexture;
    this.southTexture = southTexture;
    this.eastTexture = eastTexture;
    this.westTexture = westTexture;

    this.engineObject =
        new EngineObject(
            null,
            Database.getInstance().getMazeTexture(northTexture).getTexture(),
            Database.getInstance().getMazeTexture(southTexture).getTexture(),
            Database.getInstance().getMazeTexture(eastTexture).getTexture(),
            Database.getInstance().getMazeTexture(westTexture).getTexture(),
            0,
            false,
            null,
            null);
  }
 /*-------------------------------------------------------------------------*/
 public void renameItem(String newName) {
   SwingEditor.instance.setDirty(SwingEditor.Tab.DIFFICULTY_LEVELS);
   DifficultyLevel current =
       Database.getInstance().getDifficultyLevels().get((String) names.getSelectedValue());
   Database.getInstance().getDifficultyLevels().remove(current.getName());
   current.setName(newName);
   Database.getInstance().getDifficultyLevels().put(current.getName(), current);
   refreshNames(newName);
 }
  /*-------------------------------------------------------------------------*/
  public void copyItem(String newName) {
    SwingEditor.instance.setDirty(SwingEditor.Tab.DIFFICULTY_LEVELS);
    DifficultyLevel current =
        Database.getInstance().getDifficultyLevels().get((String) names.getSelectedValue());

    try {
      DifficultyLevel dl = current.getClass().newInstance();
      dl.setName(newName);
      Database.getInstance().getDifficultyLevels().put(dl.getName(), dl);
      refreshNames(newName);
    } catch (Exception x) {
      throw new MazeException(x);
    }
  }
  /*-------------------------------------------------------------------------*/
  public FoeTypeSelection(int dirtyFlag) {
    this.dirtyFlag = dirtyFlag;
    List<String> foeTypesList =
        new ArrayList<String>(Database.getInstance().getFoeTypes().keySet());

    Collections.sort(foeTypesList);
    int max = foeTypesList.size();
    checkBoxes = new HashMap<String, JCheckBox>();

    JPanel panel = new JPanel(new GridLayout(max / 2 + 2, 2, 3, 3));

    selectAll = new JButton("Select All");
    selectAll.addActionListener(this);
    selectNone = new JButton("Select None");
    selectNone.addActionListener(this);

    panel.add(selectAll);
    panel.add(selectNone);

    for (String s : foeTypesList) {
      JCheckBox cb = new JCheckBox(s);
      checkBoxes.put(s, cb);
      cb.addActionListener(this);
      panel.add(cb);
    }

    JScrollPane scroller = new JScrollPane(panel);
    this.add(scroller);
  }
 /*-------------------------------------------------------------------------*/
 public List<FoeType> getFoeTypes() {
   List<FoeType> result = new ArrayList<FoeType>();
   for (JCheckBox cb : checkBoxes.values()) {
     if (cb.isSelected()) {
       result.add(Database.getInstance().getFoeTypes().get(cb.getText()));
     }
   }
   return result;
 }
 /*-------------------------------------------------------------------------*/
 public void initForeignKeys() {
   Vector<String> vec = new Vector<String>(Database.getInstance().getBodyParts().keySet());
   Collections.sort(vec);
   head.setModel(new DefaultComboBoxModel(vec));
   torso.setModel(new DefaultComboBoxModel(vec));
   leg.setModel(new DefaultComboBoxModel(vec));
   hand.setModel(new DefaultComboBoxModel(vec));
   foot.setModel(new DefaultComboBoxModel(vec));
 }
  /*-------------------------------------------------------------------------*/
  public void refresh(String name) {
    if (name == null) {
      return;
    }

    DifficultyLevel dl = Database.getInstance().getDifficultyLevels().get(name);

    impl.setText(dl.getClass().getName());
    sortOrder.setValue(dl.getSortOrder());
  }
  /*-------------------------------------------------------------------------*/
  public void commit(String name) {
    // custom impls only supported
    if (name == null) {
      return;
    }

    Map<String, DifficultyLevel> difficultyLevels = Database.getInstance().getDifficultyLevels();

    try {
      Class clazz = Class.forName(impl.getText());
      DifficultyLevel dl = (DifficultyLevel) clazz.newInstance();
      dl.setName(name);
      dl.setSortOrder((Integer) sortOrder.getValue());
      difficultyLevels.put(name, dl);
    } catch (Exception x) {
      throw new MazeException(x);
    }
  }
 /*-------------------------------------------------------------------------*/
 public BodyPart getFoot() {
   return Database.getInstance().getBodyPart((String) foot.getSelectedItem());
 }
 /*-------------------------------------------------------------------------*/
 public BodyPart getHand() {
   return Database.getInstance().getBodyPart((String) hand.getSelectedItem());
 }
 /*-------------------------------------------------------------------------*/
 public BodyPart getLeg() {
   return Database.getInstance().getBodyPart((String) leg.getSelectedItem());
 }
 /*-------------------------------------------------------------------------*/
 public BodyPart getTorso() {
   return Database.getInstance().getBodyPart((String) torso.getSelectedItem());
 }
 /*-------------------------------------------------------------------------*/
 public void newItem(String name) {
   SwingEditor.instance.setDirty(SwingEditor.Tab.DIFFICULTY_LEVELS);
   DifficultyLevel dl = new DifficultyLevel();
   Database.getInstance().getDifficultyLevels().put(name, dl);
   refreshNames(name);
 }
 /*-------------------------------------------------------------------------*/
 public Vector loadData() {
   Vector<String> vec = new Vector<String>(Database.getInstance().getDifficultyLevels().keySet());
   Collections.sort(vec);
   return vec;
 }
 /*-------------------------------------------------------------------------*/
 public void deleteItem() {
   SwingEditor.instance.setDirty(SwingEditor.Tab.DIFFICULTY_LEVELS);
   String name = (String) names.getSelectedValue();
   Database.getInstance().getDifficultyLevels().remove(name);
   refreshNames(null);
 }