View Javadoc

1   package erland.game.tileadventure;
2   
3   import erland.game.component.*;
4   import erland.game.tileadventure.rect.RectBlockContainerData;
5   import erland.util.ParameterSerializable;
6   import erland.util.ParameterValueStorageExInterface;
7   
8   import javax.swing.*;
9   import java.awt.*;
10  
11  /*
12   * Copyright (C) 2004 Erland Isaksson (erland_i@hotmail.com)
13   *
14   * This program is free software; you can redistribute it and/or
15   * modify it under the terms of the GNU General Public License
16   * as published by the Free Software Foundation; either version 2
17   * of the License, or (at your option) any later version.
18   *
19   * This program is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22   * GNU General Public License for more details.
23   *
24   * You should have received a copy of the GNU General Public License
25   * along with this program; if not, write to the Free Software
26   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27   * 
28   */
29  
30  public class MapObjectEditor extends TileMapEditor {
31      /*** The draw map implementation to use */
32      protected DrawMap drawMap;
33      /*** The level manager to use */
34      protected LevelManager levelManager;
35      /*** The panel with settings for the tile */
36      protected EPanel settingsPanel;
37      /*** The walkable setting checkbox */
38      protected ECheckBox walkableCheckbox;
39      /*** The pushable setting checkbox */
40      protected ECheckBox pushableCheckbox;
41      /*** The alive setting checkbox */
42      protected ECheckBox aliveCheckbox;
43      /*** The enemy type setting list box panel */
44      protected EPanel enemyTypePanel;
45      /*** The enemy type setting list box */
46      protected EListBox enemyTypeListbox;
47      /*** The enemy type setting list box label*/
48      protected ELabel enemyTypeLabel;
49      /*** The height setting spinner panel */
50      protected EPanel heightPanel;
51      /*** The label of height of the block */
52      protected ELabel heightLabel;
53      /*** The spinner for height of the block */
54      protected ENumberSpinner heightSpinner;
55      /*** The extra object information */
56      protected MapObjectExtendedLevelInfo extendedLevelInfo;
57      /*** The level manager to use for palette bitmap */
58      protected LevelManager paletteLevelManager;
59      /*** The palette bitmap */
60      protected Image paletteBitmap;
61  
62  
63      protected String getLevelFileLabel() {
64          return null;  //To change body of implemented methods use File | Settings | File Templates.
65      }
66  
67      protected String getLevelFileGroupLabel() {
68          return null;  //To change body of implemented methods use File | Settings | File Templates.
69      }
70  
71      protected int getSizeX() {
72          return 1;
73      }
74  
75      protected int getSizeY() {
76          return 1;
77      }
78  
79      protected int getSizeZ() {
80          return 1;
81      }
82  
83      protected int getSelectSizeX() {
84          return 2;
85      }
86  
87      protected int getSelectSizeY() {
88          return 10;
89      }
90  
91      protected int getMaxHeight() {
92          return 0;
93      }
94  
95      protected Image getMapBlockImage() {
96          if(paletteBitmap==null) {
97              paletteBitmap = paletteLevelManager.getImage();
98          }
99          return paletteBitmap;
100     }
101 
102     public void drawMapBlocks(Graphics g, MapObjectContainerInterface blocks) {
103         drawMap.setContainer(getMapContainer());
104         drawMap.removeAllObjectMaps();
105         drawMap.addObjectMap(blocks);
106         drawMap.draw(g);
107     }
108 
109     public void drawSelectedFrame(Graphics g, MapObjectInterface selectedBlock) {
110         g.setColor(Color.WHITE);
111         int x1 = selectedBlock.getContainer().getPixelDrawingPositionX(selectedBlock.getPosX(),selectedBlock.getPosY(),selectedBlock.getPosZ());
112         int y1 = selectedBlock.getContainer().getPixelDrawingPositionY(selectedBlock.getPosX(),selectedBlock.getPosY(),selectedBlock.getPosZ());
113         int x2 = selectedBlock.getContainer().getPixelDrawingPositionX(selectedBlock.getPosX(),selectedBlock.getPosY()+1,selectedBlock.getPosZ());
114         int y2 = selectedBlock.getContainer().getPixelDrawingPositionY(selectedBlock.getPosX(),selectedBlock.getPosY()+1,selectedBlock.getPosZ());
115         int x3 = selectedBlock.getContainer().getPixelDrawingPositionX(selectedBlock.getPosX()+1,selectedBlock.getPosY(),selectedBlock.getPosZ());
116         int y3 = selectedBlock.getContainer().getPixelDrawingPositionY(selectedBlock.getPosX()+1,selectedBlock.getPosY(),selectedBlock.getPosZ());
117         int x4 = selectedBlock.getContainer().getPixelDrawingPositionX(selectedBlock.getPosX()+1,selectedBlock.getPosY()+1,selectedBlock.getPosZ());
118         int y4 = selectedBlock.getContainer().getPixelDrawingPositionY(selectedBlock.getPosX()+1,selectedBlock.getPosY()+1,selectedBlock.getPosZ());
119         g.drawLine(x1,y1,x2,y2);
120         g.drawLine(x1,y1,x3,y3);
121         g.drawLine(x4,y4,x2,y2);
122         g.drawLine(x4,y4,x3,y3);
123     }
124 
125     public void drawHoveringFrame(Graphics g, int posX, int posY) {
126         g.setColor(Color.WHITE);
127         int x1 = getMapContainer().getPixelDrawingPositionX(posX,posY,getMapPosZ());
128         int y1 = getMapContainer().getPixelDrawingPositionY(posX,posY,getMapPosZ());
129         int x2 = getMapContainer().getPixelDrawingPositionX(posX,posY+1,getMapPosZ());
130         int y2 = getMapContainer().getPixelDrawingPositionY(posX,posY+1,getMapPosZ());
131         int x3 = getMapContainer().getPixelDrawingPositionX(posX+1,posY,getMapPosZ());
132         int y3 = getMapContainer().getPixelDrawingPositionY(posX+1,posY,getMapPosZ());
133         int x4 = getMapContainer().getPixelDrawingPositionX(posX+1,posY+1,getMapPosZ());
134         int y4 = getMapContainer().getPixelDrawingPositionY(posX+1,posY+1,getMapPosZ());
135         g.drawLine(x1,y1,x2,y2);
136         g.drawLine(x1,y1,x3,y3);
137         g.drawLine(x4,y4,x2,y2);
138         g.drawLine(x4,y4,x3,y3);
139     }
140 
141     protected LevelManager getLevelManager() {
142         levelManager.setContainer(getMapContainer());
143         return levelManager;
144     }
145 
146     protected void initFinish() {
147         super.initFinish();
148         drawMap = ((TileGameEnvironmentInterface)getEnvironment().getCustomEnvironment()).createBlockMap();
149         levelManager = new MapObjectEditorLevelManager();
150         levelManager.init(getEnvironment());
151         paletteLevelManager = new AnimationEditorLevelManager();
152         paletteLevelManager.init(getEnvironment());
153         paletteBitmap = null;
154 
155         settingsPanel = EPanel.create();
156         settingsPanel.getContainer().setSize(getEnvironment().getScreenHandler().getWidth()*2/5, getEnvironment().getScreenHandler().getHeight()/2);
157         settingsPanel.getContainer().setLocation(10,100);
158 
159         settingsPanel.getContainer().setLayout(new BoxLayout(settingsPanel.getContainer(), BoxLayout.Y_AXIS));
160         getEnvironment().getScreenHandler().add(settingsPanel.getComponent());
161         walkableCheckbox = ECheckBox.create("Walkable");
162         settingsPanel.getContainer().add(walkableCheckbox.getComponent());
163         pushableCheckbox = ECheckBox.create("Pushable");
164         settingsPanel.getContainer().add(pushableCheckbox.getComponent());
165         aliveCheckbox = ECheckBox.create("Alive");
166         settingsPanel.getContainer().add(aliveCheckbox.getComponent());
167         enemyTypePanel = EPanel.create();
168         enemyTypePanel.getContainer().setLayout(new FlowLayout());
169         enemyTypeLabel = ELabel.create("Enemy type");
170         enemyTypePanel.getContainer().add(enemyTypeLabel.getComponent());
171         enemyTypeListbox = EListBox.create(new String[] {"type1","type2","type3"});
172         enemyTypePanel.getContainer().add(enemyTypeListbox.getComponent());
173         settingsPanel.getContainer().add(enemyTypePanel.getComponent());
174         heightPanel = EPanel.create();
175         heightPanel.getContainer().setLayout(new FlowLayout());
176         heightLabel = ELabel.create("Height");
177         heightPanel.getContainer().add(heightLabel.getComponent());
178         heightSpinner = ENumberSpinner.create(1,1,10,1);
179         heightPanel.getContainer().add(heightSpinner.getComponent());
180         settingsPanel.getContainer().add(heightPanel.getComponent());
181     }
182 
183     protected void exitFinish() {
184         super.exitFinish();
185         getEnvironment().getScreenHandler().remove(settingsPanel.getComponent());
186     }
187 
188     protected void setExtendedLevelInfo(ParameterSerializable info) {
189         if(info instanceof MapObjectExtendedLevelInfo) {
190             extendedLevelInfo = (MapObjectExtendedLevelInfo) info;
191         }else {
192             extendedLevelInfo = new MapObjectExtendedLevelInfo();
193             extendedLevelInfo.setPushable(Boolean.FALSE);
194             extendedLevelInfo.setWalkable(Boolean.FALSE);
195         }
196     }
197 
198     protected ParameterSerializable getExtendedLevelInfo() {
199         if(extendedLevelInfo==null) {
200             extendedLevelInfo = new MapObjectExtendedLevelInfo();
201         }
202         extendedLevelInfo.setPushable(Boolean.valueOf(pushableCheckbox.getSelection()));
203         extendedLevelInfo.setWalkable(Boolean.valueOf(walkableCheckbox.getSelection()));
204         return extendedLevelInfo;
205     }
206 
207     protected void updateBlocks() {
208         super.updateBlocks();
209         pushableCheckbox.setSelection(extendedLevelInfo.getPushable().booleanValue());
210         walkableCheckbox.setSelection(extendedLevelInfo.getWalkable().booleanValue());
211     }
212 }