Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 835 | chris | 1 | package com.gebauz.bauzoid.menu; |
| 2 | |||
| 3 | import com.gebauz.bauzoid.game.Game; |
||
| 4 | import com.gebauz.bauzoid.graphics.sprite.Sprite; |
||
| 5 | import com.gebauz.bauzoid.parser.ScanException; |
||
| 6 | import com.gebauz.bauzoid.parser.Tokenizer; |
||
| 7 | |||
| 8 | /** Implements a Button using an Image and Text. |
||
| 9 | * |
||
| 10 | * This kind of button has several semantic changes over the regular Button class: |
||
| 11 | * - position, size, align refer to the image used |
||
| 12 | * - The text has its own position (relative to the upper-left edge of the Image) |
||
| 13 | * - The text has its own alignment |
||
| 14 | * |
||
| 15 | * |
||
| 16 | * @author chiu |
||
| 17 | * |
||
| 18 | */ |
||
| 19 | public class ImageButton extends Button |
||
| 20 | { |
||
| 21 | // Constants======================================================================================== |
||
| 22 | |||
| 23 | // Embedded Types=================================================================================== |
||
| 24 | |||
| 25 | // Fields=========================================================================================== |
||
| 26 | |||
| 27 | private String mTextureName = ""; |
||
| 28 | private String mPushTextureName = ""; |
||
| 29 | |||
| 30 | private Sprite mImage = null; |
||
| 31 | private Sprite mPushImage = null; |
||
| 32 | |||
| 33 | // Methods========================================================================================== |
||
| 34 | |||
| 35 | public ImageButton(Game game, Menu parent, String name) |
||
| 36 | { |
||
| 37 | super(game, parent, name); |
||
| 38 | } |
||
| 39 | |||
| 40 | @Override |
||
| 41 | public void init() |
||
| 42 | { |
||
| 43 | super.init(); |
||
| 44 | |||
| 45 | //mImage = new Sprite(getGame().getGraphics(), new Texture(Gdx.files.internal(mTextureName))); |
||
| 46 | mImage = new Sprite(getGame().getGraphics(), mTextureName); |
||
| 47 | mImage.init(); |
||
| 48 | Image.setSpriteProperties(mImage, this); |
||
| 49 | |||
| 50 | if (!mPushTextureName.isEmpty()) |
||
| 51 | { |
||
| 52 | //mPushImage = new Sprite(getGame().getGraphics(), new Texture(Gdx.files.internal(mPushTextureName))); |
||
| 53 | mPushImage = new Sprite(getGame().getGraphics(), mPushTextureName); |
||
| 54 | mPushImage.init(); |
||
| 55 | |||
| 56 | if (mPushImage != null) |
||
| 57 | Image.setSpriteProperties(mPushImage, this); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | @Override |
||
| 62 | public void exit() |
||
| 63 | { |
||
| 64 | if (mImage != null) |
||
| 65 | { |
||
| 66 | mImage.dispose(); |
||
| 67 | mImage = null; |
||
| 68 | } |
||
| 69 | |||
| 70 | if (mPushImage != null) |
||
| 71 | { |
||
| 72 | mPushImage.dispose(); |
||
| 73 | mPushImage = null; |
||
| 74 | } |
||
| 75 | |||
| 76 | super.exit(); |
||
| 77 | } |
||
| 78 | |||
| 79 | @Override |
||
| 80 | public void update(float deltaTime) |
||
| 81 | { |
||
| 82 | super.update(deltaTime); |
||
| 83 | |||
| 84 | mImage.update(deltaTime); |
||
| 85 | Image.setSpriteProperties(mImage, this); |
||
| 86 | if (mPushImage != null) |
||
| 87 | { |
||
| 88 | Image.setSpriteProperties(mPushImage, this); |
||
| 89 | mPushImage.update(deltaTime); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | @Override |
||
| 94 | public void render() |
||
| 95 | { |
||
| 96 | if (isButtonDown() && (mPushImage != null)) |
||
| 97 | mPushImage.render(); |
||
| 98 | else |
||
| 99 | mImage.render(); |
||
| 100 | |||
| 101 | super.render(); |
||
| 102 | } |
||
| 103 | |||
| 104 | public boolean parseLine(String identifier, Tokenizer tokenizer) throws ScanException |
||
| 105 | { |
||
| 106 | if (identifier.equalsIgnoreCase("texture")) |
||
| 107 | { |
||
| 108 | mTextureName = MenuUtil.parseString(tokenizer); |
||
| 109 | } |
||
| 110 | else if (identifier.equalsIgnoreCase("pushTexture")) |
||
| 111 | { |
||
| 112 | mPushTextureName = MenuUtil.parseString(tokenizer); |
||
| 113 | } |
||
| 114 | else |
||
| 115 | { |
||
| 116 | return super.parseLine(identifier, tokenizer); |
||
| 117 | } |
||
| 118 | return true; |
||
| 119 | } |
||
| 120 | |||
| 121 | // Getters/Setters================================================================================== |
||
| 122 | |||
| 123 | } |