[libgdx] SkeletonViewer clean up.

This commit is contained in:
NathanSweet 2017-06-01 21:14:49 +02:00
parent 088a870463
commit 1b4ac3ba8e

View File

@ -378,19 +378,19 @@ public class SkeletonViewer extends ApplicationAdapter {
Window window = new Window("Skeleton", skin); Window window = new Window("Skeleton", skin);
Table root = new Table(skin); Table root = new Table(skin);
TextButton openButton = new TextButton("Open", skin); TextButton openButton = new TextButton("Open", skin);
List<String> animationList = new List(skin); TextButton minimizeButton = new TextButton("-", skin);
ScrollPane animationScroll = new ScrollPane(animationList, skin, "bg");
List<String> skinList = new List(skin); Slider scaleSlider = new Slider(0.1f, 3, 0.01f, false, skin);
ScrollPane skinScroll = new ScrollPane(skinList, skin, "bg"); Label scaleLabel = new Label("1.0", skin);
CheckBox loopCheckbox = new CheckBox("Loop", skin); TextButton scaleResetButton = new TextButton("Reset", skin);
CheckBox premultipliedCheckbox = new CheckBox("Premultiplied", skin);
Slider mixSlider = new Slider(0, 4, 0.01f, false, skin); Slider zoomSlider = new Slider(0.01f, 10, 0.01f, false, skin);
Label mixLabel = new Label("0.3", skin); Label zoomLabel = new Label("1.0", skin);
Slider speedSlider = new Slider(0, 3, 0.01f, false, skin); TextButton zoomResetButton = new TextButton("Reset", skin);
Label speedLabel = new Label("1.0", skin);
TextButton speedResetButton = new TextButton("Reset", skin);
CheckBox flipXCheckbox = new CheckBox("X", skin); CheckBox flipXCheckbox = new CheckBox("X", skin);
CheckBox flipYCheckbox = new CheckBox("Y", skin); CheckBox flipYCheckbox = new CheckBox("Y", skin);
CheckBox debugBonesCheckbox = new CheckBox("Bones", skin); CheckBox debugBonesCheckbox = new CheckBox("Bones", skin);
CheckBox debugRegionsCheckbox = new CheckBox("Regions", skin); CheckBox debugRegionsCheckbox = new CheckBox("Regions", skin);
CheckBox debugBoundingBoxesCheckbox = new CheckBox("Bounds", skin); CheckBox debugBoundingBoxesCheckbox = new CheckBox("Bounds", skin);
@ -399,21 +399,34 @@ public class SkeletonViewer extends ApplicationAdapter {
CheckBox debugPathsCheckbox = new CheckBox("Paths", skin); CheckBox debugPathsCheckbox = new CheckBox("Paths", skin);
CheckBox debugPointsCheckbox = new CheckBox("Points", skin); CheckBox debugPointsCheckbox = new CheckBox("Points", skin);
CheckBox debugClippingCheckbox = new CheckBox("Clipping", skin); CheckBox debugClippingCheckbox = new CheckBox("Clipping", skin);
Slider scaleSlider = new Slider(0.1f, 3, 0.01f, false, skin);
Slider zoomSlider = new Slider(0.01f, 10, 0.01f, false, skin); CheckBox premultipliedCheckbox = new CheckBox("Premultiplied", skin);
Label scaleLabel = new Label("1.0", skin);
Label zoomLabel = new Label("1.0", skin);
TextButton scaleResetButton = new TextButton("Reset", skin);
TextButton zoomResetButton = new TextButton("Reset", skin);
TextButton minimizeButton = new TextButton("-", skin);
TextButton bonesSetupPoseButton = new TextButton("Bones", skin); TextButton bonesSetupPoseButton = new TextButton("Bones", skin);
TextButton slotsSetupPoseButton = new TextButton("Slots", skin); TextButton slotsSetupPoseButton = new TextButton("Slots", skin);
TextButton setupPoseButton = new TextButton("Both", skin); TextButton setupPoseButton = new TextButton("Both", skin);
Label statusLabel = new Label("", skin);
WidgetGroup toasts = new WidgetGroup(); List<String> skinList = new List(skin);
ScrollPane skinScroll = new ScrollPane(skinList, skin, "bg");
ButtonGroup<TextButton> trackButtons = new ButtonGroup(); ButtonGroup<TextButton> trackButtons = new ButtonGroup();
CheckBox loopCheckbox = new CheckBox("Loop", skin);
Slider alphaSlider = new Slider(0, 1, 0.01f, false, skin); Slider alphaSlider = new Slider(0, 1, 0.01f, false, skin);
Label alphaLabel = new Label("1.0", skin); Label alphaLabel = new Label("1.0", skin);
List<String> animationList = new List(skin);
ScrollPane animationScroll = new ScrollPane(animationList, skin, "bg");
Slider speedSlider = new Slider(0, 3, 0.01f, false, skin);
Label speedLabel = new Label("1.0", skin);
TextButton speedResetButton = new TextButton("Reset", skin);
Slider mixSlider = new Slider(0, 4, 0.01f, false, skin);
Label mixLabel = new Label("0.3", skin);
Label statusLabel = new Label("", skin);
WidgetGroup toasts = new WidgetGroup();
boolean prefsLoaded; boolean prefsLoaded;
UI () { UI () {
@ -472,7 +485,7 @@ public class SkeletonViewer extends ApplicationAdapter {
{ {
Table table = table(); Table table = table();
table.add(scaleLabel).width(29); table.add(scaleLabel).width(29);
table.add(scaleSlider).fillX().expandX(); table.add(scaleSlider).growX();
table.add(scaleResetButton); table.add(scaleResetButton);
root.add(table).fill().row(); root.add(table).fill().row();
} }
@ -480,7 +493,7 @@ public class SkeletonViewer extends ApplicationAdapter {
{ {
Table table = table(); Table table = table();
table.add(zoomLabel).width(29); table.add(zoomLabel).width(29);
table.add(zoomSlider).fillX().expandX(); table.add(zoomSlider).growX();
table.add(zoomResetButton); table.add(zoomResetButton);
root.add(table).fill().row(); root.add(table).fill().row();
} }
@ -501,7 +514,7 @@ public class SkeletonViewer extends ApplicationAdapter {
root.add("Setup pose:"); root.add("Setup pose:");
root.add(table(bonesSetupPoseButton, slotsSetupPoseButton, setupPoseButton)).row(); root.add(table(bonesSetupPoseButton, slotsSetupPoseButton, setupPoseButton)).row();
root.add("Skin:"); root.add("Skin:");
root.add(skinScroll).expand().fill().minHeight(64).row(); root.add(skinScroll).grow().minHeight(64).row();
root.add(new Image(skin.newDrawable("white", new Color(0x4e4e4eff)))).height(1).fillX().colspan(2).pad(1, 0, 1, 0).row(); root.add(new Image(skin.newDrawable("white", new Color(0x4e4e4eff)))).height(1).fillX().colspan(2).pad(1, 0, 1, 0).row();
@ -517,16 +530,16 @@ public class SkeletonViewer extends ApplicationAdapter {
{ {
Table table = table(); Table table = table();
table.add(alphaLabel).width(29); table.add(alphaLabel).width(29);
table.add(alphaSlider).fillX().expandX(); table.add(alphaSlider).growX();
root.add(table).fill().row(); root.add(table).fill().row();
} }
root.add("Animation:"); root.add("Animation:");
root.add(animationScroll).expand().fill().minHeight(64).row(); root.add(animationScroll).grow().minHeight(64).row();
root.add("Speed:"); root.add("Speed:");
{ {
Table table = table(); Table table = table();
table.add(speedLabel).width(29); table.add(speedLabel).width(29);
table.add(speedSlider).fillX().expandX(); table.add(speedSlider).growX();
table.add(speedResetButton); table.add(speedResetButton);
root.add(table).fill().row(); root.add(table).fill().row();
} }
@ -534,11 +547,11 @@ public class SkeletonViewer extends ApplicationAdapter {
{ {
Table table = table(); Table table = table();
table.add(mixLabel).width(29); table.add(mixLabel).width(29);
table.add(mixSlider).fillX().expandX(); table.add(mixSlider).growX();
root.add(table).fill().row(); root.add(table).fill().row();
} }
window.add(root).expand().fill(); window.add(root).grow();
window.pack(); window.pack();
stage.addActor(window); stage.addActor(window);
@ -613,7 +626,7 @@ public class SkeletonViewer extends ApplicationAdapter {
minimizeButton.setText("+"); minimizeButton.setText("+");
} else { } else {
window.getCells().get(0).setActor(root); window.getCells().get(0).setActor(root);
ui.window.setHeight(Gdx.graphics.getHeight() / uiScale + 8); window.setHeight(Gdx.graphics.getHeight() / uiScale + 8);
minimizeButton.setText("-"); minimizeButton.setText("-");
} }
} }
@ -639,7 +652,7 @@ public class SkeletonViewer extends ApplicationAdapter {
public void changed (ChangeEvent event, Actor actor) { public void changed (ChangeEvent event, Actor actor) {
zoomLabel.setText(Float.toString((int)(zoomSlider.getValue() * 100) / 100f)); zoomLabel.setText(Float.toString((int)(zoomSlider.getValue() * 100) / 100f));
float newZoom = 1 / zoomSlider.getValue(); float newZoom = 1 / zoomSlider.getValue();
camera.position.x -= ui.window.getWidth() / 2 * (newZoom - camera.zoom); camera.position.x -= window.getWidth() / 2 * (newZoom - camera.zoom);
camera.zoom = newZoom; camera.zoom = newZoom;
} }
}); });
@ -689,7 +702,7 @@ public class SkeletonViewer extends ApplicationAdapter {
if (state != null) { if (state != null) {
String name = animationList.getSelected(); String name = animationList.getSelected();
if (name == null) if (name == null)
state.setEmptyAnimation(trackButtons.getCheckedIndex(), ui.mixSlider.getValue()); state.setEmptyAnimation(trackButtons.getCheckedIndex(), mixSlider.getValue());
else else
setAnimation(); setAnimation();
} }
@ -717,7 +730,7 @@ public class SkeletonViewer extends ApplicationAdapter {
ChangeListener trackButtonListener = new ChangeListener() { ChangeListener trackButtonListener = new ChangeListener() {
public void changed (ChangeEvent event, Actor actor) { public void changed (ChangeEvent event, Actor actor) {
int track = ui.trackButtons.getCheckedIndex(); int track = trackButtons.getCheckedIndex();
if (track == -1) return; if (track == -1) return;
TrackEntry current = state.getCurrent(track); TrackEntry current = state.getCurrent(track);
animationList.getSelection().setProgrammaticChangeEvents(false); animationList.getSelection().setProgrammaticChangeEvents(false);
@ -801,10 +814,10 @@ public class SkeletonViewer extends ApplicationAdapter {
} }
void render () { void render () {
if (state != null && state.getCurrent(ui.trackButtons.getCheckedIndex()) == null) { if (state != null && state.getCurrent(trackButtons.getCheckedIndex()) == null) {
ui.animationList.getSelection().setProgrammaticChangeEvents(false); animationList.getSelection().setProgrammaticChangeEvents(false);
ui.animationList.setSelected(null); animationList.setSelected(null);
ui.animationList.getSelection().setProgrammaticChangeEvents(true); animationList.getSelection().setProgrammaticChangeEvents(true);
} }
statusLabel.pack(); statusLabel.pack();