⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boardeditor.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        butBoardNew = new Button(Messages.getString("BoardEditor.butBoardNew")); //$NON-NLS-1$        butBoardNew.setActionCommand( "fileBoardNew" ); //$NON-NLS-1$        butBoardNew.addActionListener(this);        butBoardLoad = new Button(Messages.getString("BoardEditor.butBoardLoad")); //$NON-NLS-1$        butBoardLoad.setActionCommand( "fileBoardOpen" ); //$NON-NLS-1$        butBoardLoad.addActionListener(this);        butBoardSave = new Button(Messages.getString("BoardEditor.butBoardSave")); //$NON-NLS-1$        butBoardSave.setActionCommand( "fileBoardSave" ); //$NON-NLS-1$        butBoardSave.addActionListener(this);        butBoardSaveAs = new Button(Messages.getString("BoardEditor.butBoardSaveAs")); //$NON-NLS-1$        butBoardSaveAs.setActionCommand( "fileBoardSaveAs" ); //$NON-NLS-1$        butBoardSaveAs.addActionListener(this);        butBoardSaveAsImage = new Button(Messages.getString("BoardEditor.butBoardSaveAsImage")); //$NON-NLS-1$        butBoardSaveAsImage.setActionCommand( "fileBoardSaveAsImage" ); //$NON-NLS-1$        butBoardSaveAsImage.addActionListener(this);        panButtons = new Panel(new GridLayout(3, 2, 2, 2));        panButtons.add(labBoard);        panButtons.add(butBoardNew);        panButtons.add(butBoardLoad);        panButtons.add(butBoardSave);        panButtons.add(butBoardSaveAs);        panButtons.add(butBoardSaveAsImage);                blankL = new Label("", Label.CENTER); //$NON-NLS-1$                GridBagLayout gridbag = new GridBagLayout();        GridBagConstraints c = new GridBagConstraints();        setLayout(gridbag);                c.fill = GridBagConstraints.HORIZONTAL;        c.weightx = 0.0;    c.weighty = 0.0;        c.insets = new Insets(4, 4, 1, 1);                c.gridwidth = GridBagConstraints.REMAINDER;         addBag(canHex, gridbag, c);        c.gridwidth = 1;         addBag(labElev, gridbag, c);        addBag(butElevUp, gridbag, c);        addBag(butElevDown, gridbag, c);        c.gridwidth = GridBagConstraints.REMAINDER;         addBag(texElev, gridbag, c);                addBag(labTerrain, gridbag, c);        addBag(lisTerrain, gridbag, c);        addBag(butDelTerrain, gridbag, c);        addBag(panTerrainType, gridbag, c);        addBag(panTerrExits, gridbag, c);        addBag(panRoads, gridbag, c);        addBag(labTheme, gridbag, c);        addBag(texTheme, gridbag, c);        addBag(butAddTerrain, gridbag, c);        addBag(butMiniMap, gridbag, c);            c.weightx = 1.0;    c.weighty = 1.0;        addBag(blankL, gridbag, c);                c.weightx = 1.0;    c.weighty = 0.0;        //        addBag(labBoard, gridbag, c);        addBag(panButtons, gridbag, c);        minimapW = new Dialog(frame, Messages.getString("BoardEditor.minimapW"), false); //$NON-NLS-1$        minimapW.setLocation(GUIPreferences.getInstance().getMinimapPosX(), GUIPreferences.getInstance().getMinimapPosY());        try {            minimap = new MiniMap(minimapW, game, bv);        } catch (IOException e) {            new AlertDialog(frame,Messages.getString("BoardEditor.FatalError"), Messages.getString("BoardEditor.CouldNotInitialiseMinimap")+e); //$NON-NLS-1$ //$NON-NLS-2$            frame.dispose();        }        minimapW.add(minimap);        setMapVisible(true);    }        private void addBag(Component comp, GridBagLayout gridbag, GridBagConstraints c) {        gridbag.setConstraints(comp, c);        add(comp);    }        /**     * Apply the current Hex to the Board at the specified     * location.     */    public void paintHex(Coords c) {        board.setHex(c, curHex.duplicate());    }        /**     * Apply the current Hex to the Board at the specified     * location.     */    public void resurfaceHex(Coords c) {        if(board.contains(c)) {            IHex newHex = curHex.duplicate();            newHex.setElevation(board.getHex(c).getElevation());            board.setHex(c, newHex);        }    }    /**     * Apply the current Hex to the Board at the specified     * location.     */    public void addToHex(Coords c) {        if(board.contains(c)) {            IHex newHex = curHex.duplicate();            IHex oldHex = board.getHex(c);            newHex.setElevation(oldHex.getElevation());            for(int i=0;i<Terrains.SIZE;i++) {                if(!newHex.containsTerrain(i)                        && oldHex.containsTerrain(i)) {                    newHex.addTerrain(oldHex.getTerrain(i));                }            }            board.setHex(c, newHex);        }    }    /**     * Sets the current hex     *      * @param hex            hex to set.     */    public void setCurrentHex(IHex hex) {        curHex = hex.duplicate();                texElev.setText(Integer.toString(curHex.getElevation()));                    refreshTerrainList();                if (lisTerrain.getItemCount() > 0) {            lisTerrain.select(0);            refreshTerrainFromList();        }                texTheme.setText(curHex.getTheme());        repaint();        repaintWorkingHex();    }        private void repaintWorkingHex() {        if (curHex != null) {            TilesetManager tm = bv.getTilesetManager();            tm.clearHex(curHex);        }        canHex.repaint();        lastClicked = null;    }    /**     * Refreshes the terrain list to match the current hex     */    public void refreshTerrainList() {        lisTerrain.removeAll();        for (int i = 0; i < Terrains.SIZE; i++) {            ITerrain terrain = curHex.getTerrain(i);            if (terrain != null) {                lisTerrain.add(terrain.toString());            }        }    }        /**     * Returns a new instance of the terrain that is currently entered in the     * terrain input fields     */    private ITerrain enteredTerrain() {        int type = Terrains.getType(choTerrainType.getSelectedItem());        int level = Integer.parseInt(texTerrainLevel.getText());        boolean exitsSpecified = cheTerrExitSpecified.getState();        int exits = Integer.parseInt(texTerrExits.getText());        return Terrains.getTerrainFactory().createTerrain(type, level, exitsSpecified, exits);    }        /**     * Add or set the terrain to the list based on the fields.     */    private void addSetTerrain() {        ITerrain toAdd = enteredTerrain();        curHex.addTerrain(toAdd);        refreshTerrainList();        repaintWorkingHex();    }        /**     * Set all the appropriate terrain field to match the currently selected     * terrain in the list.     */    private void refreshTerrainFromList() {        ITerrain terrain = Terrains.getTerrainFactory().createTerrain(lisTerrain.getSelectedItem());        terrain = curHex.getTerrain(terrain.getType());        choTerrainType.select(Terrains.getName(terrain.getType()));        texTerrainLevel.setText(Integer.toString(terrain.getLevel()));        cheTerrExitSpecified.setState(terrain.hasExitsSpecified());        texTerrExits.setText(Integer.toString(terrain.getExits()));    }        /**     * Initialize a new data set in the current board.     *      * If hexes are loaded, brings up a dialog box requesting     * width and height and default hex.  If height and width     * are valid, creates new board data and fills it with the     * selected hex.     */    public void boardNewXX() {        // display new board dialog        BoardNewDialog bnd = new BoardNewDialog(frame, lisTerrain.getItems(), lisTerrain.getSelectedIndex());        bnd.setLocation(frame.getLocation().x + 150, frame.getLocation().y + 100);        bnd.setVisible(true);                if(bnd.getX() > 0 || bnd.getY() > 0) {            IHex[] newHexes = new IHex[ bnd.getX() * bnd.getY() ];             for(int i = 0; i < newHexes.length; i++) {                 newHexes[i] = new Hex();             }            board.newData(bnd.getX(), bnd.getY(), newHexes);             curpath = null;            curfile = null;            frame.setTitle(Messages.getString("BoardEditor.title")); //$NON-NLS-1$            menuBar.setBoard( true );        }    }        public void boardNew() {        RandomMapDialog rmd = new RandomMapDialog(frame, this, mapSettings);        rmd.setVisible(true);                board = BoardUtilities.generateRandom(mapSettings);        game.setBoard(board);        curpath = null;        curfile = null;        frame.setTitle(Messages.getString("BoardEditor.title")); //$NON-NLS-1$        menuBar.setBoard( true );    }        public void updateMapSettings(MapSettings newSettings) {        mapSettings = newSettings;    }        public void boardLoad() {        FileDialog fd = new FileDialog(frame, Messages.getString("BoardEditor.loadBoard"), FileDialog.LOAD); //$NON-NLS-1$        fd.setDirectory("data" + File.separator + "boards"); //$NON-NLS-1$ //$NON-NLS-2$        fd.setLocation(frame.getLocation().x + 150, frame.getLocation().y + 100);        fd.setVisible(true);                if(fd.getFile() == null) {            // I want a file, y'know!            return;        }        curpath = fd.getDirectory();        curfile = fd.getFile();        // load!        try {            InputStream is = new FileInputStream(new File(curpath, curfile));            // tell the board to load!            board.load(is);            // okay, done!            is.close();            menuBar.setBoard( true );        } catch(IOException ex) {            System.err.println("error opening file to save!"); //$NON-NLS-1$            System.err.println(ex);        }                frame.setTitle(Messages.getString("BoardEditor.title0") + curfile); //$NON-NLS-1$        cheRoadsAutoExit.setState( board.getRoadsAutoExit() );        refreshTerrainList();    }    /**     * Checks to see if there is already a path and name     * stored; if not, calls "save as"; otherwise, saves      * the board to the specified file.     */    public void boardSave() {        if(curfile == null) {            boardSaveAs();            return;        }        // save!        try {            OutputStream os = new FileOutputStream(new File(curpath, curfile));            // tell the board to save!            board.save(os);            // okay, done!            os.close();        } catch(IOException ex) {            System.err.println("error opening file to save!"); //$NON-NLS-1$            System.err.println(ex);        }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -