gdx-studio
git clone https://git.pyrossh.dev/gdx-studio
An IDE for creating Games using libgdx and Java supported on all platforms Android, iOS, Desktop
src/scene2d/ImageJson.java
| a9b2a64 | 1 | package scene2d; |
| a62d533 | 2 | import com.badlogic.gdx.scenes.scene2d.ui.Image; |
| a62d533 | 3 | import com.badlogic.gdx.utils.Json; |
| a62d533 | 4 | import com.badlogic.gdx.utils.JsonValue; |
| a62d533 | 5 | |
| a62d533 | 6 | |
| a62d533 | 7 | public class ImageJson extends Image implements Json.Serializer<ImageJson> {
|
| a62d533 | 8 | private String texName = ""; |
| a62d533 | 9 | public EffectType effectType = EffectType.None; |
| a62d533 | 10 | public float effectValue = 0f; |
| a62d533 | 11 | public float effectDuration = 0f; |
| a62d533 | 12 | public InterpolationType interpolationType = InterpolationType.Linear; |
| a62d533 | 13 | public float addActorDelay = 0f; |
| a62d533 | 14 | public float addEffectDelay = 0f; |
| a62d533 | 15 | |
| a62d533 | 16 | public EventType evtType = EventType.None; |
| a9b2a64 | 17 | public Scene.OnEventType onEvtType = Scene.OnEventType.DoEffect; |
| a62d533 | 18 | public String eventScene = ""; |
| a62d533 | 19 | |
| a62d533 | 20 | |
| a62d533 | 21 | public ImageJson(){
|
| a62d533 | 22 | |
| a62d533 | 23 | } |
| a62d533 | 24 | |
| a62d533 | 25 | /* |
| a62d533 | 26 | * The texture name |
| a62d533 | 27 | * */ |
| a62d533 | 28 | public ImageJson(String texName){
|
| a62d533 | 29 | super(Asset.tex(texName)); |
| a62d533 | 30 | this.texName = texName; |
| a62d533 | 31 | } |
| a62d533 | 32 | |
| a62d533 | 33 | @Override |
| a62d533 | 34 | public ImageJson read(Json arg0, JsonValue jv, Class arg2) {
|
| a62d533 | 35 | final ImageJson image = new ImageJson(jv.getString("texName"));
|
| a62d533 | 36 | Serializer.ActorSerializer.readActor(jv, image); |
| a62d533 | 37 | image.effectType = EffectType.valueOf(jv.getString("effect"));
|
| a62d533 | 38 | image.effectDuration = jv.getFloat("duration");
|
| a62d533 | 39 | image.effectValue = jv.getFloat("value");
|
| a62d533 | 40 | image.interpolationType = InterpolationType.valueOf(jv.getString("interpolation"));
|
| a62d533 | 41 | image.addActorDelay = jv.getFloat("addActorDelay");
|
| a62d533 | 42 | image.addEffectDelay = jv.getFloat("addEffectDelay");
|
| a62d533 | 43 | |
| a62d533 | 44 | image.evtType = EventType.valueOf(jv.getString("event"));
|
| a9b2a64 | 45 | image.onEvtType = Scene.OnEventType.valueOf(jv.getString("onEvent"));
|
| a62d533 | 46 | image.eventScene = jv.getString("eventScene");
|
| a62d533 | 47 | createEvent(image); |
| a62d533 | 48 | return image; |
| a62d533 | 49 | } |
| a62d533 | 50 | |
| a62d533 | 51 | void createEvent(final ImageJson image){
|
| a62d533 | 52 | switch(image.evtType){
|
| a62d533 | 53 | case SceneCreated: |
| a62d533 | 54 | checkOnEventType(image); |
| a62d533 | 55 | break; |
| a62d533 | 56 | case Clicked: |
| a62d533 | 57 | break; |
| a62d533 | 58 | case Dispose: |
| a62d533 | 59 | break; |
| a62d533 | 60 | case Dragged: |
| a62d533 | 61 | break; |
| a62d533 | 62 | case GestureDown: |
| a62d533 | 63 | break; |
| a62d533 | 64 | case GestureLeft: |
| a62d533 | 65 | break; |
| a62d533 | 66 | case GestureRight: |
| a62d533 | 67 | break; |
| a62d533 | 68 | case GestureUp: |
| a62d533 | 69 | break; |
| a62d533 | 70 | case Moved: |
| a62d533 | 71 | break; |
| a62d533 | 72 | case Pause: |
| a62d533 | 73 | break; |
| a62d533 | 74 | case Resume: |
| a62d533 | 75 | break; |
| a62d533 | 76 | case TouchedDown: |
| a62d533 | 77 | break; |
| a62d533 | 78 | case TouchedUp: |
| a62d533 | 79 | break; |
| a62d533 | 80 | case None: |
| a62d533 | 81 | break; |
| a62d533 | 82 | default: |
| a62d533 | 83 | break; |
| a62d533 | 84 | } |
| a62d533 | 85 | } |
| a62d533 | 86 | |
| a62d533 | 87 | void checkOnEventType(ImageJson image){
|
| a62d533 | 88 | switch(image.onEvtType){
|
| a62d533 | 89 | case DoEffect:Effect.createEffect(image);break; |
| a62d533 | 90 | //case SetScene:Stage.setScene(image.eventScene);break; |
| a62d533 | 91 | default:break; |
| a62d533 | 92 | } |
| a62d533 | 93 | } |
| a62d533 | 94 | |
| a62d533 | 95 | @Override |
| a62d533 | 96 | public void write(Json json, ImageJson image, Class arg2) {
|
| a62d533 | 97 | json.writeObjectStart(); |
| a62d533 | 98 | Serializer.ActorSerializer.writeActor(json, image); |
| a62d533 | 99 | json.writeValue("texName", image.getTexName());
|
| a62d533 | 100 | json.writeValue("effect", image.effectType.toString());
|
| a62d533 | 101 | json.writeValue("value", image.effectValue);
|
| a62d533 | 102 | json.writeValue("duration", image.effectDuration);
|
| a62d533 | 103 | json.writeValue("interpolation", image.interpolationType.toString());
|
| a62d533 | 104 | json.writeValue("addActorDelay", image.addActorDelay);
|
| a62d533 | 105 | json.writeValue("addEffectDelay", image.addActorDelay);
|
| a62d533 | 106 | |
| a62d533 | 107 | json.writeValue("event", image.evtType.toString());
|
| a62d533 | 108 | json.writeValue("onEvent", image.onEvtType.toString());
|
| a62d533 | 109 | json.writeValue("eventScene", image.eventScene);
|
| a62d533 | 110 | json.writeObjectEnd(); |
| a62d533 | 111 | } |
| a62d533 | 112 | |
| a62d533 | 113 | public String getTexName(){
|
| a62d533 | 114 | return texName; |
| a62d533 | 115 | } |
| a62d533 | 116 | } |