private List<String> createTestList() { // Create behavior names int numBehaviors = tests.length; String[] behaviorNames = new String[numBehaviors]; for (int i = 0; i < numBehaviors; i++) { behaviorNames[i] = tests[i].testName; } final List<String> behaviorsList = new List<String>(skin); behaviorsList.setItems(behaviorNames); behaviorsList.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { if (!behaviorSelectionWindow.isCollapsed() && getTapCount() == 2) { changeTest(behaviorsList.getSelectedIndex()); behaviorSelectionWindow.collapse(); } } }); return behaviorsList; }
void events() { window.addListener( new InputListener() { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.cancel(); return true; } }); openButton.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { FileDialog fileDialog = new FileDialog((Frame) null, "Choose skeleton file"); fileDialog.setMode(FileDialog.LOAD); fileDialog.setVisible(true); String name = fileDialog.getFile(); String dir = fileDialog.getDirectory(); if (name == null || dir == null) return; loadSkeleton(new FileHandle(new File(dir, name).getAbsolutePath())); } }); setupPoseButton.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { if (skeleton != null) skeleton.setToSetupPose(); } }); bonesSetupPoseButton.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { if (skeleton != null) skeleton.setBonesToSetupPose(); } }); slotsSetupPoseButton.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { if (skeleton != null) skeleton.setSlotsToSetupPose(); } }); minimizeButton.addListener( new ClickListener() { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.cancel(); return super.touchDown(event, x, y, pointer, button); } public void clicked(InputEvent event, float x, float y) { if (minimizeButton.isChecked()) { window.getCells().get(0).setActor(null); window.setHeight(37); minimizeButton.setText("+"); } else { window.getCells().get(0).setActor(root); ui.window.setHeight(Gdx.graphics.getHeight() + 8); minimizeButton.setText("-"); } } }); scaleSlider.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { scaleLabel.setText(Float.toString((int) (scaleSlider.getValue() * 100) / 100f)); if (!scaleSlider.isDragging()) loadSkeleton(skeletonFile); } }); speedSlider.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { speedLabel.setText(Float.toString((int) (speedSlider.getValue() * 100) / 100f)); } }); alphaSlider.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { alphaLabel.setText(Float.toString((int) (alphaSlider.getValue() * 100) / 100f)); int track = trackButtons.getCheckedIndex(); if (track > 0) { TrackEntry current = state.getCurrent(track); if (current != null) { current.setAlpha(alphaSlider.getValue()); current.resetRotationDirections(); } } } }); mixSlider.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { mixLabel.setText(Float.toString((int) (mixSlider.getValue() * 100) / 100f)); if (state != null) state.getData().setDefaultMix(mixSlider.getValue()); } }); animationList.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { if (state != null) { String name = animationList.getSelected(); if (name == null) state.setEmptyAnimation(trackButtons.getCheckedIndex(), ui.mixSlider.getValue()); else setAnimation(); } } }); loopCheckbox.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { setAnimation(); } }); skinList.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { if (skeleton != null) { String skinName = skinList.getSelected(); if (skinName == null) skeleton.setSkin((Skin) null); else skeleton.setSkin(skinName); skeleton.setSlotsToSetupPose(); } } }); ChangeListener trackButtonListener = new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { int track = ui.trackButtons.getCheckedIndex(); if (track == -1) return; TrackEntry current = state.getCurrent(track); animationList.getSelection().setProgrammaticChangeEvents(false); animationList.setSelected(current == null ? null : current.animation.name); animationList.getSelection().setProgrammaticChangeEvents(true); alphaSlider.setDisabled(track == 0); alphaSlider.setValue(current == null ? 1 : current.alpha); } }; for (TextButton button : trackButtons.getButtons()) button.addListener(trackButtonListener); Gdx.input.setInputProcessor( new InputMultiplexer( stage, new InputAdapter() { public boolean touchDown(int screenX, int screenY, int pointer, int button) { touchDragged(screenX, screenY, pointer); return false; } public boolean touchDragged(int screenX, int screenY, int pointer) { skeletonX = screenX; skeletonY = Gdx.graphics.getHeight() - screenY; return false; } public boolean touchUp(int screenX, int screenY, int pointer, int button) { savePrefs(); return false; } })); ChangeListener savePrefsListener = new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { if (actor instanceof Slider && ((Slider) actor).isDragging()) return; savePrefs(); } }; debugBonesCheckbox.addListener(savePrefsListener); debugRegionsCheckbox.addListener(savePrefsListener); debugMeshHullCheckbox.addListener(savePrefsListener); debugMeshTrianglesCheckbox.addListener(savePrefsListener); debugPathsCheckbox.addListener(savePrefsListener); premultipliedCheckbox.addListener(savePrefsListener); loopCheckbox.addListener(savePrefsListener); speedSlider.addListener(savePrefsListener); mixSlider.addListener(savePrefsListener); scaleSlider.addListener(savePrefsListener); animationList.addListener(savePrefsListener); skinList.addListener(savePrefsListener); }
public LevelEditorGameState(GameStateManager gsm) { super(gsm); bitmapFont = new BitmapFont(); stage = new Stage(); Skin skin = new Skin(Gdx.files.internal("uiskin.json")); Label titleLabel = new Label("Level Editor", skin); stage.addActor(titleLabel); Table table = new Table(); stage.addActor(table); table.setSize(V_WIDTH / 3, V_HEIGHT); table.setPosition(0, 0); table.debug(); // show debug shit int i = 0; for (E_TOOL e : E_TOOL.values()) { // for use in the input listener final E_TOOL temp = e; TextButton b = new TextButton(e.name(), skin); b.addListener( new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { current_Tool = temp; return false; } }); if (++i % 2 == 0) { table.row(); } table.add(b); } table.row(); table.add(new Label("Zoom", skin)); zoomSlider = new Slider(0.1f, 10.0f, 0.1f, false, skin); zoomSlider.addListener( new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { cam.zoom = zoom = zoomSlider.getValue(); } }); table.add(zoomSlider); table.row(); table.add(new Label("Grid", skin)); gridSlider = new Slider(1, 20, 1, false, skin); gridSlider.addListener( new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { gridSize = (int) gridSlider.getValue(); } }); table.add(gridSlider); final List pointTypeList = new List(skin); pointTypeList.setItems(Point.TYPE.values()); pointTypeList.addListener( new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { point_Type = (Point.TYPE) pointTypeList.getSelected(); } }); final List shapeTypeList = new List(skin); shapeTypeList.setItems(Shape.TYPE.values()); shapeTypeList.addListener( new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { shape_Type = (Shape.TYPE) shapeTypeList.getSelected(); } }); table.row(); table.add(pointTypeList); table.row(); table.add(shapeTypeList); current_Tool = E_TOOL.SELECT; point_Type = Point.TYPE.SPAWN; shape_Type = Shape.TYPE.WALL; gridSize = 2; width = V_WIDTH; height = V_HEIGHT; zoom = 5; cam.zoom = zoom; filename = "blacklevel.lvl"; loadLevel(filename); setInputProcessor(new InputMultiplexer(stage, new EditorInputAdapter())); }