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/Serializer.java
| a9b2a64 | 1 | package scene2d; |
| a62d533 | 2 | import com.badlogic.gdx.graphics.Color; |
| a62d533 | 3 | import com.badlogic.gdx.scenes.scene2d.Actor; |
| a62d533 | 4 | import com.badlogic.gdx.scenes.scene2d.Group; |
| 7c84877 | 5 | import com.badlogic.gdx.scenes.scene2d.Touchable; |
| a62d533 | 6 | import com.badlogic.gdx.scenes.scene2d.ui.Button; |
| a62d533 | 7 | import com.badlogic.gdx.scenes.scene2d.ui.CheckBox; |
| a62d533 | 8 | import com.badlogic.gdx.scenes.scene2d.ui.Dialog; |
| a62d533 | 9 | import com.badlogic.gdx.scenes.scene2d.ui.Label; |
| a62d533 | 10 | import com.badlogic.gdx.scenes.scene2d.ui.List; |
| a62d533 | 11 | import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; |
| a62d533 | 12 | import com.badlogic.gdx.scenes.scene2d.ui.SelectBox; |
| a62d533 | 13 | import com.badlogic.gdx.scenes.scene2d.ui.Slider; |
| a62d533 | 14 | import com.badlogic.gdx.scenes.scene2d.ui.SplitPane; |
| a62d533 | 15 | import com.badlogic.gdx.scenes.scene2d.ui.Stack; |
| a62d533 | 16 | import com.badlogic.gdx.scenes.scene2d.ui.Table; |
| a62d533 | 17 | import com.badlogic.gdx.scenes.scene2d.ui.TextButton; |
| a62d533 | 18 | import com.badlogic.gdx.scenes.scene2d.ui.TextField; |
| a62d533 | 19 | import com.badlogic.gdx.scenes.scene2d.ui.Touchpad; |
| a62d533 | 20 | import com.badlogic.gdx.scenes.scene2d.ui.Tree; |
| 7c84877 | 21 | import com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup; |
| 7c84877 | 22 | import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup; |
| 7c84877 | 23 | import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup; |
| a62d533 | 24 | import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle; |
| a62d533 | 25 | import com.badlogic.gdx.utils.Json; |
| a62d533 | 26 | import com.badlogic.gdx.utils.JsonValue; |
| a62d533 | 27 | |
| a62d533 | 28 | public class Serializer {
|
| a62d533 | 29 | |
| a9b2a64 | 30 | public static void registerSerializer(Class<?> clazz, Json.Serializer serializer){
|
| a9b2a64 | 31 | Scene.json.setSerializer(clazz, serializer); |
| a62d533 | 32 | } |
| a62d533 | 33 | |
| a9b2a64 | 34 | public static void setup(){
|
| a62d533 | 35 | registerSerializer(Actor.class, new ActorSerializer()); |
| 7c84877 | 36 | registerSerializer(Scene.class, new SceneSerializer()); |
| a62d533 | 37 | registerSerializer(ImageJson.class, new ImageJson()); |
| a62d533 | 38 | registerSerializer(Label.class, new LabelSerializer()); |
| a62d533 | 39 | registerSerializer(Button.class, new ButtonSerializer()); |
| a62d533 | 40 | registerSerializer(TextButton.class, new TextButtonSerializer()); |
| a62d533 | 41 | registerSerializer(Table.class, new TableSerializer()); |
| a62d533 | 42 | registerSerializer(CheckBox.class, new CheckBoxSerializer()); |
| a62d533 | 43 | registerSerializer(SelectBox.class, new SelectBoxSerializer()); |
| a62d533 | 44 | registerSerializer(List.class, new ListSerializer()); |
| a62d533 | 45 | registerSerializer(Slider.class, new SliderSerializer()); |
| a62d533 | 46 | registerSerializer(TextField.class, new TextFieldSerializer()); |
| a62d533 | 47 | registerSerializer(Touchpad.class, new TouchpadSerializer()); |
| a62d533 | 48 | registerSerializer(Sprite.class, new SpriteSerializer()); |
| 7c84877 | 49 | |
| 7c84877 | 50 | registerSerializer(Dialog.class, new DialogSerializer()); |
| 7c84877 | 51 | registerSerializer(SplitPane.class, new SplitPaneSerializer()); |
| 7c84877 | 52 | registerSerializer(ScrollPane.class, new ScrollPaneSerializer()); |
| 7c84877 | 53 | registerSerializer(Stack.class, new StackSerializer()); |
| 7c84877 | 54 | registerSerializer(Tree.class, new TreeSerializer()); |
| 7c84877 | 55 | registerSerializer(Table.class, new TableSerializer()); |
| 7c84877 | 56 | registerSerializer(ButtonGroup.class, new ButtonGroupSerializer()); |
| 7c84877 | 57 | registerSerializer(HorizontalGroup.class, new HorizontalGroupSerializer()); |
| 7c84877 | 58 | registerSerializer(VerticalGroup.class, new VerticalGroupSerializer()); |
| a62d533 | 59 | } |
| a62d533 | 60 | |
| a62d533 | 61 | public static class ActorSerializer implements Json.Serializer<Actor> {
|
| a62d533 | 62 | |
| a62d533 | 63 | @Override |
| a62d533 | 64 | public Actor read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 65 | Actor actor = new Actor(); |
| a62d533 | 66 | readActor(jv, actor); |
| a62d533 | 67 | return actor; |
| a62d533 | 68 | } |
| a62d533 | 69 | |
| a62d533 | 70 | @Override |
| a62d533 | 71 | public void write(Json json, Actor actor, Class arg2) {
|
| a62d533 | 72 | json.writeObjectStart(); |
| a62d533 | 73 | writeActor(json, actor); |
| a62d533 | 74 | json.writeObjectEnd(); |
| a62d533 | 75 | } |
| a62d533 | 76 | |
| a62d533 | 77 | public static void readActor(JsonValue jv, Actor actor){
|
| a62d533 | 78 | actor.setName(jv.getString("name"));
|
| a62d533 | 79 | actor.setX(jv.getFloat("x"));
|
| a62d533 | 80 | actor.setY(jv.getFloat("y"));
|
| a62d533 | 81 | actor.setWidth(jv.getFloat("width"));
|
| a62d533 | 82 | actor.setHeight(jv.getFloat("height"));
|
| 7c84877 | 83 | actor.setOriginX(jv.getFloat("ox"));
|
| 7c84877 | 84 | actor.setOriginY(jv.getFloat("oy"));
|
| 7c84877 | 85 | actor.setRotation(jv.getFloat("rotation"));
|
| a62d533 | 86 | actor.setColor(Color.valueOf(jv.getString("color")));
|
| 7c84877 | 87 | actor.setTouchable(Touchable.valueOf(jv.getString("touchable")));
|
| 7c84877 | 88 | actor.setVisible(jv.getBoolean("visible"));
|
| a9b2a64 | 89 | Scene.getCurrentScene().addActor(actor); |
| a9b2a64 | 90 | actor.setZIndex(jv.getInt("zindex"));
|
| a62d533 | 91 | } |
| a62d533 | 92 | |
| a62d533 | 93 | public static void writeActor(Json json, Actor actor){
|
| a62d533 | 94 | json.writeValue("class", actor.getClass().getName());
|
| a62d533 | 95 | json.writeValue("name", actor.getName());
|
| a62d533 | 96 | json.writeValue("x", actor.getX());
|
| a62d533 | 97 | json.writeValue("y", actor.getY());
|
| a62d533 | 98 | json.writeValue("width", actor.getWidth());
|
| a62d533 | 99 | json.writeValue("height", actor.getHeight());
|
| a62d533 | 100 | json.writeValue("ox", actor.getOriginX());
|
| a62d533 | 101 | json.writeValue("oy", actor.getOriginY());
|
| a62d533 | 102 | json.writeValue("rotation", actor.getRotation());
|
| 7c84877 | 103 | json.writeValue("zindex", actor.getZIndex());
|
| 7c84877 | 104 | json.writeValue("color", actor.getColor().toString());
|
| 7c84877 | 105 | json.writeValue("touchable", actor.getTouchable().toString());
|
| 7c84877 | 106 | json.writeValue("visible", actor.isVisible());
|
| a62d533 | 107 | } |
| a62d533 | 108 | |
| a62d533 | 109 | } |
| 7c84877 | 110 | |
| 7c84877 | 111 | public static class SceneSerializer extends ActorSerializer {
|
| a62d533 | 112 | @Override |
| a62d533 | 113 | public Actor read(Json json, JsonValue jv, Class arg2) {
|
| a9b2a64 | 114 | Scene scene = Scene.getCurrentScene(); |
| 7c84877 | 115 | scene.sceneBackground = jv.getString("background");
|
| 7c84877 | 116 | scene.sceneMusic = jv.getString("music");
|
| 7c84877 | 117 | scene.sceneTransition = jv.getString("transition");
|
| 7c84877 | 118 | scene.sceneDuration = jv.getFloat("duration");
|
| 7c84877 | 119 | scene.sceneInterpolationType = InterpolationType.valueOf(jv.getString("interpolation"));
|
| a9b2a64 | 120 | Scene.log(Scene.getCurrentScene().getName()); |
| a9b2a64 | 121 | Scene.getRoot().addActor(scene); |
| 7c84877 | 122 | return scene; |
| a62d533 | 123 | } |
| a62d533 | 124 | |
| a62d533 | 125 | @Override |
| 7c84877 | 126 | public void write(Json json, Actor label, Class arg2) {
|
| a62d533 | 127 | json.writeObjectStart(); |
| 7c84877 | 128 | Scene scene = (Scene) label; |
| a9b2a64 | 129 | json.writeValue("class", Scene.class.getName());
|
| 7c84877 | 130 | json.writeValue("background", scene.sceneBackground);
|
| 7c84877 | 131 | json.writeValue("music", scene.sceneMusic);
|
| 7c84877 | 132 | json.writeValue("transition", scene.sceneTransition);
|
| 7c84877 | 133 | json.writeValue("duration", scene.sceneDuration);
|
| 7c84877 | 134 | json.writeValue("interpolation", scene.sceneInterpolationType.toString());
|
| a62d533 | 135 | json.writeObjectEnd(); |
| a62d533 | 136 | } |
| a62d533 | 137 | } |
| a62d533 | 138 | |
| 7c84877 | 139 | public static class LabelSerializer extends ActorSerializer {
|
| a62d533 | 140 | |
| a62d533 | 141 | @Override |
| a62d533 | 142 | public Actor read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 143 | LabelStyle ls = new LabelStyle(); |
| a62d533 | 144 | ls.font = Asset.font(jv.getString("fontName"));
|
| a62d533 | 145 | Label label = new Label(jv.getString("text"), ls);
|
| a62d533 | 146 | readActor(jv, label); |
| a62d533 | 147 | return label; |
| a62d533 | 148 | } |
| a62d533 | 149 | |
| a62d533 | 150 | @Override |
| a62d533 | 151 | public void write(Json json, Actor label, Class arg2) {
|
| a62d533 | 152 | json.writeObjectStart(); |
| a62d533 | 153 | writeActor(json, label); |
| a62d533 | 154 | json.writeValue("text", ((Label)label).getText().toString());
|
| a62d533 | 155 | json.writeValue("fontName", Asset.fontMap.getKey(((Label)label).getStyle().font, false));
|
| a62d533 | 156 | json.writeObjectEnd(); |
| a62d533 | 157 | } |
| a62d533 | 158 | } |
| a62d533 | 159 | |
| a62d533 | 160 | public static class ButtonSerializer extends ActorSerializer {
|
| a62d533 | 161 | |
| a62d533 | 162 | @Override |
| a62d533 | 163 | public Actor read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 164 | Button btn = new Button(Asset.skin); |
| a62d533 | 165 | readActor(jv, btn); |
| a62d533 | 166 | return btn; |
| a62d533 | 167 | } |
| a62d533 | 168 | |
| a62d533 | 169 | @Override |
| a62d533 | 170 | public void write(Json json, Actor btn, Class arg2) {
|
| a62d533 | 171 | json.writeObjectStart(); |
| a62d533 | 172 | writeActor(json, btn); |
| a62d533 | 173 | json.writeObjectEnd(); |
| a62d533 | 174 | } |
| a62d533 | 175 | |
| a62d533 | 176 | } |
| a62d533 | 177 | |
| a62d533 | 178 | private static class CheckBoxSerializer extends ActorSerializer {
|
| a62d533 | 179 | |
| a62d533 | 180 | @Override |
| a62d533 | 181 | public Actor read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 182 | CheckBox check = new CheckBox(jv.getString("text"), Asset.skin);
|
| a9b2a64 | 183 | readActor(jv, check); |
| a62d533 | 184 | return check; |
| a62d533 | 185 | } |
| a62d533 | 186 | |
| a62d533 | 187 | @Override |
| a62d533 | 188 | public void write(Json json, Actor check, Class arg2) {
|
| a62d533 | 189 | json.writeObjectStart(); |
| a9b2a64 | 190 | writeActor(json, check); |
| a62d533 | 191 | json.writeValue("text", ((CheckBox)check).getText().toString());
|
| a62d533 | 192 | json.writeObjectEnd(); |
| a62d533 | 193 | } |
| a62d533 | 194 | |
| a62d533 | 195 | } |
| a62d533 | 196 | |
| a62d533 | 197 | private static class SliderSerializer extends ActorSerializer {
|
| a62d533 | 198 | |
| a62d533 | 199 | @Override |
| a62d533 | 200 | public Actor read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 201 | Slider slider = new Slider(jv.getFloat("min"),jv.getFloat("max"),jv.getFloat("step")
|
| a62d533 | 202 | , false, Asset.skin); |
| a62d533 | 203 | slider.setValue(jv.getFloat("value"));
|
| a62d533 | 204 | readActor(jv, slider); |
| a62d533 | 205 | return slider; |
| a62d533 | 206 | } |
| a62d533 | 207 | |
| a62d533 | 208 | @Override |
| a62d533 | 209 | public void write(Json json, Actor slider, Class arg2) {
|
| a62d533 | 210 | json.writeObjectStart(); |
| a62d533 | 211 | writeActor(json, slider); |
| a62d533 | 212 | json.writeValue("min", ((Slider)slider).getMinValue());
|
| a62d533 | 213 | json.writeValue("max", ((Slider)slider).getMaxValue());
|
| a62d533 | 214 | json.writeValue("step", ((Slider)slider).getStepSize());
|
| a62d533 | 215 | json.writeValue("value", ((Slider)slider).getValue());
|
| a62d533 | 216 | json.writeObjectEnd(); |
| a62d533 | 217 | } |
| a62d533 | 218 | } |
| a62d533 | 219 | |
| a62d533 | 220 | private static class SelectBoxSerializer extends ActorSerializer {
|
| a62d533 | 221 | |
| a62d533 | 222 | @Override |
| a62d533 | 223 | public Actor read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 224 | SelectBox select = new SelectBox(jv.getString("text").split(","), Asset.skin);
|
| a62d533 | 225 | readActor(jv, select); |
| a62d533 | 226 | return select; |
| a62d533 | 227 | } |
| a62d533 | 228 | |
| a62d533 | 229 | @Override |
| a62d533 | 230 | public void write(Json json, Actor select, Class arg2) {
|
| a62d533 | 231 | json.writeObjectStart(); |
| a62d533 | 232 | writeActor(json, select); |
| a62d533 | 233 | String items = ""; |
| a62d533 | 234 | for(String s: ((SelectBox)select).getItems()) |
| a62d533 | 235 | items+=s+","; |
| a62d533 | 236 | json.writeValue("text", items);
|
| a62d533 | 237 | json.writeObjectEnd(); |
| a62d533 | 238 | } |
| a62d533 | 239 | |
| a62d533 | 240 | } |
| a62d533 | 241 | |
| a62d533 | 242 | private static class ListSerializer extends ActorSerializer {
|
| a62d533 | 243 | |
| a62d533 | 244 | @Override |
| a62d533 | 245 | public Actor read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 246 | List list = new List(jv.getString("text").split(","), Asset.skin);
|
| a9b2a64 | 247 | readActor(jv, list); |
| a62d533 | 248 | return list; |
| a62d533 | 249 | } |
| a62d533 | 250 | |
| a62d533 | 251 | @Override |
| a62d533 | 252 | public void write(Json json, Actor list, Class arg2) {
|
| a62d533 | 253 | json.writeObjectStart(); |
| a9b2a64 | 254 | writeActor(json, list); |
| a62d533 | 255 | String items = ""; |
| a62d533 | 256 | for(String s: ((List)list).getItems()) |
| a62d533 | 257 | items+=s+","; |
| a62d533 | 258 | json.writeValue("text", items);
|
| a62d533 | 259 | json.writeObjectEnd(); |
| a62d533 | 260 | } |
| a62d533 | 261 | |
| a62d533 | 262 | } |
| a62d533 | 263 | |
| a62d533 | 264 | public static class TouchpadSerializer extends ActorSerializer {
|
| a62d533 | 265 | public static float deadZoneRadius = 5f; |
| a62d533 | 266 | @Override |
| a62d533 | 267 | public Actor read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 268 | Touchpad tp = new Touchpad(jv.getFloat("deadzoneRadius"), Asset.skin);
|
| a62d533 | 269 | deadZoneRadius = jv.getFloat("deadzoneRadius");
|
| a9b2a64 | 270 | readActor(jv, tp); |
| a62d533 | 271 | return tp; |
| a62d533 | 272 | } |
| a62d533 | 273 | |
| a62d533 | 274 | @Override |
| a62d533 | 275 | public void write(Json json, Actor tp, Class arg2) {
|
| a62d533 | 276 | json.writeObjectStart(); |
| a9b2a64 | 277 | writeActor(json, tp); |
| a62d533 | 278 | json.writeValue("deadzoneRadius", deadZoneRadius);
|
| a62d533 | 279 | json.writeObjectEnd(); |
| a62d533 | 280 | } |
| a62d533 | 281 | } |
| a62d533 | 282 | |
| a62d533 | 283 | private static class TextFieldSerializer extends ActorSerializer {
|
| a62d533 | 284 | |
| a62d533 | 285 | @Override |
| a62d533 | 286 | public Actor read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 287 | TextField tf = new TextField(jv.getString("text"), Asset.skin);
|
| a62d533 | 288 | readActor(jv, tf); |
| a62d533 | 289 | return tf; |
| a62d533 | 290 | } |
| a62d533 | 291 | |
| a62d533 | 292 | @Override |
| a62d533 | 293 | public void write(Json json, Actor tf, Class arg2) {
|
| a62d533 | 294 | json.writeObjectStart(); |
| a62d533 | 295 | writeActor(json, tf); |
| a62d533 | 296 | json.writeValue("text", ((TextField)tf).getText().toString());
|
| a62d533 | 297 | json.writeObjectEnd(); |
| a62d533 | 298 | } |
| a62d533 | 299 | } |
| a62d533 | 300 | |
| a62d533 | 301 | private static class TextButtonSerializer extends ActorSerializer {
|
| a62d533 | 302 | |
| a62d533 | 303 | @Override |
| a62d533 | 304 | public Actor read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 305 | TextButton btn = new TextButton(jv.getString("text"), Asset.skin);
|
| a62d533 | 306 | ActorSerializer.readActor(jv, btn); |
| a62d533 | 307 | return btn; |
| a62d533 | 308 | } |
| a62d533 | 309 | |
| a62d533 | 310 | @Override |
| a62d533 | 311 | public void write(Json json, Actor btn, Class arg2) {
|
| a62d533 | 312 | json.writeObjectStart(); |
| a62d533 | 313 | ActorSerializer.writeActor(json, btn); |
| a62d533 | 314 | json.writeValue("text", ((TextButton)btn).getText().toString());
|
| a62d533 | 315 | json.writeObjectEnd(); |
| a62d533 | 316 | } |
| a62d533 | 317 | } |
| 7c84877 | 318 | |
| 7c84877 | 319 | |
| a62d533 | 320 | |
| 7c84877 | 321 | private static class SpriteSerializer extends ActorSerializer {
|
| 7c84877 | 322 | |
| 7c84877 | 323 | @Override |
| 7c84877 | 324 | public Actor read(Json arg0, JsonValue jv, Class arg2) {
|
| 7c84877 | 325 | Sprite sprite; |
| 7c84877 | 326 | if(jv.getInt("frameCount") != 1){
|
| 7c84877 | 327 | sprite = new Sprite(jv.getString("textures").split(",")[0], jv.getInt("frameCount"),
|
| 7c84877 | 328 | jv.getFloat("duration"));
|
| 7c84877 | 329 | } |
| 7c84877 | 330 | else{
|
| 7c84877 | 331 | sprite = new Sprite(jv.getFloat("duration"), jv.getString("textures").split(","));
|
| 7c84877 | 332 | } |
| a9b2a64 | 333 | |
| 7c84877 | 334 | sprite.isAnimationActive = jv.getBoolean("active");
|
| 7c84877 | 335 | sprite.isAnimationLooping = jv.getBoolean("looping");
|
| a9b2a64 | 336 | ActorSerializer.readActor(jv, sprite); |
| 7c84877 | 337 | return sprite; |
| 7c84877 | 338 | } |
| 7c84877 | 339 | |
| 7c84877 | 340 | |
| 7c84877 | 341 | @Override |
| 7c84877 | 342 | public void write(Json json, Actor sprite, Class arg2) {
|
| 7c84877 | 343 | json.writeObjectStart(); |
| 7c84877 | 344 | ActorSerializer.writeActor(json, sprite); |
| 7c84877 | 345 | json.writeValue("textures", sprite.toString());
|
| 7c84877 | 346 | json.writeValue("duration", ((Sprite)sprite).getDuration());
|
| 7c84877 | 347 | json.writeValue("active", ((Sprite)sprite).isAnimationActive);
|
| 7c84877 | 348 | json.writeValue("looping", ((Sprite)sprite).isAnimationLooping);
|
| 7c84877 | 349 | json.writeValue("frameCount", ((Sprite)sprite).getFrameCount());
|
| 7c84877 | 350 | json.writeObjectEnd(); |
| 7c84877 | 351 | } |
| 7c84877 | 352 | |
| 7c84877 | 353 | } |
| 7c84877 | 354 | |
| 7c84877 | 355 | public static class GroupSerializer implements Json.Serializer<Group> {
|
| 7c84877 | 356 | |
| 7c84877 | 357 | @Override |
| 7c84877 | 358 | public Group read(Json json, JsonValue jv, Class arg2) {
|
| 7c84877 | 359 | Group group = new Group(); |
| 7c84877 | 360 | readGroup(jv, group); |
| 7c84877 | 361 | return group; |
| 7c84877 | 362 | } |
| 7c84877 | 363 | |
| 7c84877 | 364 | @Override |
| 7c84877 | 365 | public void write(Json json, Group group, Class arg2) {
|
| 7c84877 | 366 | json.writeObjectStart(); |
| 7c84877 | 367 | writeGroup(json, group); |
| 7c84877 | 368 | json.writeObjectEnd(); |
| 7c84877 | 369 | } |
| 7c84877 | 370 | |
| 7c84877 | 371 | public void writeGroup(Json json, Group group){
|
| 7c84877 | 372 | ActorSerializer.writeActor(json, group); |
| 7c84877 | 373 | //Array<String> actorsJson = new Array<String>(); |
| 7c84877 | 374 | //for(Actor actor: group.getChildren()){
|
| 7c84877 | 375 | // actorsJson.add(Stage.json.toJson(actor)); |
| 7c84877 | 376 | //} |
| 7c84877 | 377 | //json.writeValue("children", actorsJson, Array.class, String.class);
|
| 7c84877 | 378 | //not working |
| 7c84877 | 379 | } |
| 7c84877 | 380 | |
| 7c84877 | 381 | public void readGroup(JsonValue jv, Group group){
|
| 7c84877 | 382 | ActorSerializer.readActor(jv, group); |
| 7c84877 | 383 | //Array<String> array = (Array<String>)Stage.json.readValue(Array.class, String.class, |
| 7c84877 | 384 | // jv.get("children"));
|
| 7c84877 | 385 | //for(String actorJson: array.items){
|
| 7c84877 | 386 | // Stage.log(actorJson); |
| 7c84877 | 387 | // //group.addActor(Stage.json.fromJson(actor)); |
| 7c84877 | 388 | //} |
| 7c84877 | 389 | } |
| 7c84877 | 390 | |
| 7c84877 | 391 | public void iterateActors(){
|
| 7c84877 | 392 | |
| 7c84877 | 393 | } |
| 7c84877 | 394 | } |
| 7c84877 | 395 | |
| 7c84877 | 396 | private static class DialogSerializer extends ActorSerializer {
|
| a62d533 | 397 | |
| a62d533 | 398 | @Override |
| a62d533 | 399 | public Actor read(Json json, JsonValue jv, Class arg2) {
|
| 7c84877 | 400 | Dialog dialog = new Dialog(jv.getString("title"), Asset.skin);
|
| 7c84877 | 401 | dialog.setModal(jv.getBoolean("modal"));
|
| 7c84877 | 402 | dialog.setMovable(jv.getBoolean("move"));
|
| 7c84877 | 403 | dialog.setResizable(jv.getBoolean("resize"));
|
| a9b2a64 | 404 | readActor(jv, dialog); |
| 7c84877 | 405 | return dialog; |
| 7c84877 | 406 | } |
| 7c84877 | 407 | |
| 7c84877 | 408 | @Override |
| 7c84877 | 409 | public void write(Json json, Actor dialog, Class arg2) {
|
| 7c84877 | 410 | json.writeObjectStart(); |
| 7c84877 | 411 | writeActor(json, dialog); |
| 7c84877 | 412 | json.writeValue("title", ((Dialog)dialog).getTitle());
|
| 7c84877 | 413 | json.writeValue("modal", ((Dialog)dialog).isModal());
|
| 7c84877 | 414 | json.writeValue("move", ((Dialog)dialog).isMovable());
|
| 7c84877 | 415 | json.writeValue("resize", ((Dialog)dialog).isResizable());
|
| 7c84877 | 416 | json.writeObjectEnd(); |
| 7c84877 | 417 | } |
| 7c84877 | 418 | |
| 7c84877 | 419 | } |
| 7c84877 | 420 | |
| 7c84877 | 421 | private static class SplitPaneSerializer extends GroupSerializer {
|
| 7c84877 | 422 | |
| 7c84877 | 423 | @Override |
| 7c84877 | 424 | public Group read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 425 | SplitPane label = new SplitPane(null, null, false, Asset.skin); |
| 7c84877 | 426 | readGroup(jv, label); |
| a62d533 | 427 | return label; |
| a62d533 | 428 | } |
| a62d533 | 429 | |
| a62d533 | 430 | @Override |
| 7c84877 | 431 | public void write(Json json, Group label, Class arg2) {
|
| a62d533 | 432 | json.writeObjectStart(); |
| 7c84877 | 433 | writeGroup(json, label); |
| a62d533 | 434 | json.writeObjectEnd(); |
| a62d533 | 435 | } |
| a62d533 | 436 | } |
| a62d533 | 437 | |
| 7c84877 | 438 | private static class ScrollPaneSerializer extends GroupSerializer {
|
| a62d533 | 439 | |
| a62d533 | 440 | @Override |
| 7c84877 | 441 | public Group read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 442 | ScrollPane label = new ScrollPane(null); |
| 7c84877 | 443 | readGroup(jv, label); |
| a62d533 | 444 | return label; |
| a62d533 | 445 | } |
| a62d533 | 446 | |
| a62d533 | 447 | @Override |
| 7c84877 | 448 | public void write(Json json, Group label, Class arg2) {
|
| a62d533 | 449 | json.writeObjectStart(); |
| 7c84877 | 450 | writeGroup(json, label); |
| a62d533 | 451 | json.writeObjectEnd(); |
| a62d533 | 452 | } |
| a62d533 | 453 | } |
| a62d533 | 454 | |
| 7c84877 | 455 | private static class StackSerializer extends GroupSerializer {
|
| a62d533 | 456 | |
| a62d533 | 457 | @Override |
| 7c84877 | 458 | public Group read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 459 | Stack label = new Stack(); |
| 7c84877 | 460 | readGroup(jv, label); |
| a62d533 | 461 | return label; |
| a62d533 | 462 | } |
| a62d533 | 463 | |
| a62d533 | 464 | @Override |
| 7c84877 | 465 | public void write(Json json, Group label, Class arg2) {
|
| a62d533 | 466 | json.writeObjectStart(); |
| 7c84877 | 467 | writeGroup(json, label); |
| a62d533 | 468 | json.writeObjectEnd(); |
| a62d533 | 469 | } |
| a62d533 | 470 | } |
| a62d533 | 471 | |
| 7c84877 | 472 | private static class TreeSerializer extends GroupSerializer {
|
| a62d533 | 473 | |
| a62d533 | 474 | @Override |
| 7c84877 | 475 | public Group read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 476 | Tree label = new Tree(Asset.skin); |
| 7c84877 | 477 | readGroup(jv, label); |
| a62d533 | 478 | return label; |
| a62d533 | 479 | } |
| a62d533 | 480 | |
| a62d533 | 481 | @Override |
| 7c84877 | 482 | public void write(Json json, Group label, Class arg2) {
|
| a62d533 | 483 | json.writeObjectStart(); |
| 7c84877 | 484 | writeGroup(json, label); |
| a62d533 | 485 | json.writeObjectEnd(); |
| a62d533 | 486 | } |
| a62d533 | 487 | } |
| a62d533 | 488 | |
| 7c84877 | 489 | private static class TableSerializer extends GroupSerializer {
|
| a62d533 | 490 | |
| a62d533 | 491 | @Override |
| 7c84877 | 492 | public Group read(Json json, JsonValue jv, Class arg2) {
|
| a62d533 | 493 | Table table = new Table(Asset.skin); |
| 7c84877 | 494 | //table.getPadBottom() |
| 7c84877 | 495 | //table.getCell(null).get |
| 7c84877 | 496 | readGroup(jv, table); |
| a62d533 | 497 | return table; |
| a62d533 | 498 | } |
| a62d533 | 499 | |
| a62d533 | 500 | @Override |
| 7c84877 | 501 | public void write(Json json, Group table, Class arg2) {
|
| a62d533 | 502 | json.writeObjectStart(); |
| 7c84877 | 503 | writeGroup(json, table); |
| a62d533 | 504 | json.writeObjectEnd(); |
| a62d533 | 505 | } |
| a62d533 | 506 | |
| a62d533 | 507 | } |
| 7c84877 | 508 | |
| 7c84877 | 509 | private static class ButtonGroupSerializer extends GroupSerializer {
|
| a62d533 | 510 | |
| 7c84877 | 511 | @Override |
| 7c84877 | 512 | public Group read(Json json, JsonValue jv, Class arg2) {
|
| 7c84877 | 513 | Table table = new Table(Asset.skin); |
| 7c84877 | 514 | readGroup(jv, table); |
| 7c84877 | 515 | return table; |
| 7c84877 | 516 | } |
| a62d533 | 517 | |
| a62d533 | 518 | @Override |
| 7c84877 | 519 | public void write(Json json, Group table, Class arg2) {
|
| 7c84877 | 520 | json.writeObjectStart(); |
| 7c84877 | 521 | writeGroup(json, table); |
| 7c84877 | 522 | json.writeObjectEnd(); |
| a62d533 | 523 | } |
| a62d533 | 524 | |
| 7c84877 | 525 | } |
| 7c84877 | 526 | |
| 7c84877 | 527 | private static class HorizontalGroupSerializer extends GroupSerializer {
|
| a62d533 | 528 | |
| a62d533 | 529 | @Override |
| 7c84877 | 530 | public Group read(Json json, JsonValue jv, Class arg2) {
|
| 7c84877 | 531 | HorizontalGroup hg = new HorizontalGroup(); |
| 7c84877 | 532 | readGroup(jv, hg); |
| 7c84877 | 533 | return hg; |
| 7c84877 | 534 | } |
| 7c84877 | 535 | |
| 7c84877 | 536 | @Override |
| 7c84877 | 537 | public void write(Json json, Group table, Class arg2) {
|
| a62d533 | 538 | json.writeObjectStart(); |
| 7c84877 | 539 | writeGroup(json, table); |
| a62d533 | 540 | json.writeObjectEnd(); |
| a62d533 | 541 | } |
| a62d533 | 542 | |
| a62d533 | 543 | } |
| 7c84877 | 544 | |
| 7c84877 | 545 | private static class VerticalGroupSerializer extends GroupSerializer {
|
| 7c84877 | 546 | |
| 7c84877 | 547 | @Override |
| 7c84877 | 548 | public Group read(Json json, JsonValue jv, Class arg2) {
|
| 7c84877 | 549 | VerticalGroup vg = new VerticalGroup(); |
| 7c84877 | 550 | readGroup(jv, vg); |
| 7c84877 | 551 | return vg; |
| 7c84877 | 552 | } |
| a62d533 | 553 | |
| 7c84877 | 554 | @Override |
| 7c84877 | 555 | public void write(Json json, Group vg, Class arg2) {
|
| 7c84877 | 556 | json.writeObjectStart(); |
| 7c84877 | 557 | writeGroup(json, vg); |
| 7c84877 | 558 | json.writeObjectEnd(); |
| 7c84877 | 559 | } |
| 7c84877 | 560 | } |
| a62d533 | 561 | } |