View Javadoc

1   package erland.game.tileadventure;
2   
3   import erland.game.component.*;
4   import erland.game.tileadventure.rect.RectDrawMap;
5   import erland.game.tileadventure.rect.RectBlockContainerData;
6   import erland.util.ParameterSerializable;
7   import erland.util.ParameterValueStorageExInterface;
8   import erland.util.StringUtil;
9   
10  import javax.swing.*;
11  import java.awt.*;
12  
13  /*
14   * Copyright (C) 2004 Erland Isaksson (erland_i@hotmail.com)
15   *
16   * This program is free software; you can redistribute it and/or
17   * modify it under the terms of the GNU General Public License
18   * as published by the Free Software Foundation; either version 2
19   * of the License, or (at your option) any later version.
20   *
21   * This program is distributed in the hope that it will be useful,
22   * but WITHOUT ANY WARRANTY; without even the implied warranty of
23   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24   * GNU General Public License for more details.
25   *
26   * You should have received a copy of the GNU General Public License
27   * along with this program; if not, write to the Free Software
28   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
29   * 
30   */
31  
32  public class AnimationEditor extends TileMapEditor {
33      /*** The draw map implementation to use */
34      protected DrawMap drawMap;
35      /*** The level manager to use */
36      protected LevelManager levelManager;
37      /*** The panel with settings for the tile */
38      protected EPanel settingsPanel;
39      /*** The animation speed setting spinner panel */
40      protected EPanel animationSpeedPanel;
41      /*** The label of animation speed of the block */
42      protected ELabel animationSpeedLabel;
43      /*** The spinner for animation speed  of the block */
44      protected ENumberSpinner animationSpeedSpinner;
45      /*** The extra object information */
46      protected AnimationExtendedLevelInfo extendedLevelInfo;
47  
48  
49      protected String getLevelFileLabel() {
50          return null;  //To change body of implemented methods use File | Settings | File Templates.
51      }
52  
53      protected String getLevelFileGroupLabel() {
54          return null;  //To change body of implemented methods use File | Settings | File Templates.
55      }
56  
57      protected int getSizeX() {
58          return 10;
59      }
60  
61      protected int getSizeY() {
62          return 5;
63      }
64  
65      protected int getSizeZ() {
66          return 1;
67      }
68  
69      protected int getSelectSizeX() {
70          return 2;
71      }
72  
73      protected int getSelectSizeY() {
74          return 10;
75      }
76  
77      protected int getMaxHeight() {
78          return 0;
79      }
80  
81      protected Image getMapBlockImage() {
82          String prefix = ((TileGameEnvironmentInterface)getEnvironment().getCustomEnvironment()).getTileType();
83          return getEnvironment().getImageHandler().getImage(prefix+"ground.gif");
84      }
85  
86      public void drawMapBlocks(Graphics g, MapObjectContainerInterface blocks) {
87          drawMap.setContainer(getMapContainer());
88          drawMap.removeAllObjectMaps();
89          drawMap.addObjectMap(blocks);
90          drawMap.draw(g);
91      }
92  
93      public void drawSelectedFrame(Graphics g, MapObjectInterface selectedBlock) {
94          g.setColor(Color.WHITE);
95          int x1 = selectedBlock.getContainer().getPixelDrawingPositionX(selectedBlock.getPosX(),selectedBlock.getPosY(),selectedBlock.getPosZ());
96          int y1 = selectedBlock.getContainer().getPixelDrawingPositionY(selectedBlock.getPosX(),selectedBlock.getPosY(),selectedBlock.getPosZ());
97          int x2 = selectedBlock.getContainer().getPixelDrawingPositionX(selectedBlock.getPosX(),selectedBlock.getPosY()+1,selectedBlock.getPosZ());
98          int y2 = selectedBlock.getContainer().getPixelDrawingPositionY(selectedBlock.getPosX(),selectedBlock.getPosY()+1,selectedBlock.getPosZ());
99          int x3 = selectedBlock.getContainer().getPixelDrawingPositionX(selectedBlock.getPosX()+1,selectedBlock.getPosY(),selectedBlock.getPosZ());
100         int y3 = selectedBlock.getContainer().getPixelDrawingPositionY(selectedBlock.getPosX()+1,selectedBlock.getPosY(),selectedBlock.getPosZ());
101         int x4 = selectedBlock.getContainer().getPixelDrawingPositionX(selectedBlock.getPosX()+1,selectedBlock.getPosY()+1,selectedBlock.getPosZ());
102         int y4 = selectedBlock.getContainer().getPixelDrawingPositionY(selectedBlock.getPosX()+1,selectedBlock.getPosY()+1,selectedBlock.getPosZ());
103         g.drawLine(x1,y1,x2,y2);
104         g.drawLine(x1,y1,x3,y3);
105         g.drawLine(x4,y4,x2,y2);
106         g.drawLine(x4,y4,x3,y3);
107     }
108 
109     public void drawHoveringFrame(Graphics g, int posX, int posY) {
110         g.setColor(Color.WHITE);
111         int x1 = getMapContainer().getPixelDrawingPositionX(posX,posY,getMapPosZ());
112         int y1 = getMapContainer().getPixelDrawingPositionY(posX,posY,getMapPosZ());
113         int x2 = getMapContainer().getPixelDrawingPositionX(posX,posY+1,getMapPosZ());
114         int y2 = getMapContainer().getPixelDrawingPositionY(posX,posY+1,getMapPosZ());
115         int x3 = getMapContainer().getPixelDrawingPositionX(posX+1,posY,getMapPosZ());
116         int y3 = getMapContainer().getPixelDrawingPositionY(posX+1,posY,getMapPosZ());
117         int x4 = getMapContainer().getPixelDrawingPositionX(posX+1,posY+1,getMapPosZ());
118         int y4 = getMapContainer().getPixelDrawingPositionY(posX+1,posY+1,getMapPosZ());
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     protected LevelManager getLevelManager() {
126         levelManager.setContainer(getMapContainer());
127         return levelManager;
128     }
129 
130     protected void initFinish() {
131         super.initFinish();
132         drawMap = new RectDrawMap();
133         levelManager = new AnimationEditorLevelManager();
134         levelManager.init(getEnvironment());
135         settingsPanel = EPanel.create();
136         settingsPanel.getContainer().setSize(getEnvironment().getScreenHandler().getWidth()*2/5, getEnvironment().getScreenHandler().getHeight()/2);
137         settingsPanel.getContainer().setLocation(10,200);
138 
139         settingsPanel.getContainer().setLayout(new BoxLayout(settingsPanel.getContainer(), BoxLayout.Y_AXIS));
140         getEnvironment().getScreenHandler().add(settingsPanel.getComponent());
141         animationSpeedPanel = EPanel.create();
142         animationSpeedPanel.getContainer().setLayout(new FlowLayout());
143         animationSpeedLabel = ELabel.create("Speed");
144         animationSpeedPanel.getContainer().add(animationSpeedLabel.getComponent());
145         animationSpeedSpinner = ENumberSpinner.create(1,1,100,10);
146         animationSpeedPanel.getContainer().add(animationSpeedSpinner.getComponent());
147         settingsPanel.getContainer().add(animationSpeedPanel.getComponent());
148     }
149 
150     protected void exitFinish() {
151         super.exitFinish();
152         getEnvironment().getScreenHandler().remove(settingsPanel.getComponent());
153     }
154 
155     protected void setExtendedLevelInfo(ParameterSerializable info) {
156         if(info instanceof AnimationExtendedLevelInfo) {
157             extendedLevelInfo = (AnimationExtendedLevelInfo) info;
158         }else {
159             extendedLevelInfo = new AnimationExtendedLevelInfo();
160             extendedLevelInfo.setSpeed(1);
161         }
162     }
163 
164     protected ParameterSerializable getExtendedLevelInfo() {
165         if(extendedLevelInfo==null) {
166             extendedLevelInfo = new AnimationExtendedLevelInfo();
167         }
168         extendedLevelInfo.setSpeed(animationSpeedSpinner.getValue());
169         return extendedLevelInfo;
170     }
171 
172     protected void updateBlocks() {
173         super.updateBlocks();
174         animationSpeedSpinner.setValue(extendedLevelInfo.getSpeed());
175     }
176 
177     protected IrregularBlockContainerInterface getMapContainer() {
178         if(cont==null) {
179             TileGameEnvironmentInterface env = ((TileGameEnvironmentInterface)getEnvironment().getCustomEnvironment());
180             BlockContainerData cont = env.createRectBlockContainer(10,10,getSizeX(),getSizeY(),getSizeZ());
181             this.cont = cont;
182         }
183         return cont;
184     }
185 }