Skip to content

Commit 5751b4e

Browse files
committed
side panel
1 parent 65a051d commit 5751b4e

File tree

9 files changed

+190
-70
lines changed

9 files changed

+190
-70
lines changed

core/assets/img/edit.png

3.3 KB
Loading

core/assets/img/invisible.png

2.02 KB
Loading

core/assets/img/trash.png

4.79 KB
Loading

core/assets/img/visible.png

1.9 KB
Loading

core/src/com/github/mittyrobotics/PathSim.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public void create () {
5151
assets.load("img/pointp.png", Texture.class);
5252
assets.load("img/pointh.png", Texture.class);
5353
assets.load("img/pointt.png", Texture.class);
54+
assets.load("img/trash.png", Texture.class);
55+
assets.load("img/edit.png", Texture.class);
56+
assets.load("img/visible.png", Texture.class);
57+
assets.load("img/invisible.png", Texture.class);
58+
5459

5560
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("skin/Holo-dark-xhdpi.atlas"));
5661
skin = new Skin(atlas);
@@ -74,7 +79,6 @@ public void create () {
7479
// Gdx.input.setInputProcessor(Renderer2D.camController);
7580

7681
input = new InputMultiplexer();
77-
input.addProcessor(renderer2d.ui.stage);
7882
input.addProcessor(Renderer2D.camController);
7983
Gdx.input.setInputProcessor(input);
8084

@@ -145,7 +149,7 @@ public void render () {
145149
renderer2d.render();
146150
}
147151

148-
if(debug) {
152+
if(debug && !renderer2d.loading) {
149153
debugText.setText("PATH VARS\n-----\nediting path: " + PathSim.pathManager.curEditingPath + "\nediting node: " + PathSim.pathManager.curEditingNode
150154
+ "\nediting vel: " + PathSim.pathManager.curEditingVel + "\n\non path: " + PathSim.pathManager.curOnPath + "\nselected node: " + PathSim.pathManager.curSelectedNode + "\nhovering node: "
151155
+ PathSim.pathManager.curHoveringNode + "\n\nadd front/back/new: " + renderer2d.addFront + " " + renderer2d.addBack + " " + renderer2d.addNew + "\njust placed: " +

core/src/com/github/mittyrobotics/tools/CamController2D.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ public boolean touchDragged (int screenX, int screenY, int pointer) {
110110

111111
@Override
112112
public boolean scrolled (float amountX, float amountY) {
113-
if(Gdx.input.getX() <= PathSim.LEFT_WIDTH) {
113+
int x = Gdx.input.getX();
114+
int y = Gdx.graphics.getHeight() - Gdx.input.getY();
115+
if(Gdx.input.getX() <= PathSim.LEFT_WIDTH && !(x >= PathSim.renderer2d.rwx && x <= PathSim.renderer2d.rwx +
116+
PathSim.renderer2d.ww && y >= PathSim.renderer2d.rwy && y <= PathSim.renderer2d.rwy + PathSim.renderer2d.wh)) {
114117
return zoom(amountY);
115118
}
116119
return false;

core/src/com/github/mittyrobotics/tools/PathManager.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
public class PathManager {
99

1010
public ArrayList<ExtendedPath> paths = new ArrayList<>();
11+
public ArrayList<ExtendedPath> toBeDeleted = new ArrayList<>();
12+
1113
public int curEditingPath, curEditingNode, curOnPath, curEditingVel, curSelectedNode, curHoveringNode, curUIHoveringNode;
1214

1315
public Point2D storedPoint;
@@ -27,6 +29,24 @@ public void removeStoredPoint() {
2729
storedPoint = null;
2830
}
2931

32+
public void delayRemove(ExtendedPath path) {
33+
toBeDeleted.add(path);
34+
System.out.println("hi");
35+
}
36+
37+
public void updateRemove() {
38+
for(ExtendedPath p : toBeDeleted) {
39+
if(paths.indexOf(p) == curEditingPath) curEditingPath = -1;
40+
else if (paths.indexOf(p) < curEditingPath) curEditingPath--;
41+
42+
if(paths.indexOf(p) == curOnPath) curOnPath = -1;
43+
else if (paths.indexOf(p) < curOnPath) curOnPath--;
44+
paths.remove(p);
45+
PathSim.renderer2d.ui.populateWidget();
46+
}
47+
toBeDeleted.clear();
48+
}
49+
3050
public void storePoint(Point2D point) {
3151
storedPoint = point;
3252
}
@@ -35,10 +55,20 @@ public void addPathFromPoint(Point2D point) {
3555
if(storedPoint != null) {
3656
Angle angle = new Angle(point.x - storedPoint.x, point.y - storedPoint.y);
3757
paths.add(new ExtendedPath(new QuinticHermiteSplineGroup(new QuinticHermiteSpline(new Pose2D(storedPoint, angle), new Pose2D(point, angle)))));
58+
PathSim.renderer2d.ui.populateWidget();
3859
}
3960
storedPoint = null;
4061
}
4162

63+
public void chooseEditPath(ExtendedPath p) {
64+
if(paths.contains(p)) {
65+
curEditingPath = paths.indexOf(p);
66+
curSelectedNode = -1;
67+
curEditingNode = -1;
68+
curEditingVel = -1;
69+
}
70+
}
71+
4272
public QuinticHermiteSpline getNewPathPreview(Point2D point) {
4373
if(storedPoint != null) {
4474
Angle angle = new Angle(point.x - storedPoint.x, point.y - storedPoint.y);

core/src/com/github/mittyrobotics/tools/Renderer2D.java

Lines changed: 75 additions & 61 deletions
Large diffs are not rendered by default.

core/src/com/github/mittyrobotics/tools/UI.java

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import com.badlogic.gdx.Gdx;
44
import com.badlogic.gdx.Input;
55
import com.badlogic.gdx.graphics.Color;
6+
import com.badlogic.gdx.graphics.Texture;
67
import com.badlogic.gdx.scenes.scene2d.*;
78
import com.badlogic.gdx.scenes.scene2d.ui.*;
89
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
910
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
11+
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
1012
import com.badlogic.gdx.utils.Align;
1113
import com.badlogic.gdx.utils.Disposable;
1214
import com.github.mittyrobotics.PathSim;
@@ -18,8 +20,8 @@
1820
public class UI implements Disposable {
1921

2022
public Stage stage;
21-
public Table container, table, pcontainer, ptable;
22-
public ScrollPane pane, ppane;
23+
public Table container, table, pcontainer, ptable, widgetTable, widgetContainer;
24+
public ScrollPane pane, ppane, widgetPane;
2325
public int right, prevState, prevEditing;
2426
public static int addingSpline;
2527
public Label addingLabel, widget;
@@ -119,6 +121,28 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
119121
pcontainer.setBounds(right+25, 82, 250, Gdx.graphics.getHeight() - 478);
120122
pathEdit.add(pcontainer);
121123

124+
widgetTable = new Table();
125+
widgetContainer = new Table();
126+
127+
widgetPane = new ScrollPane(widgetTable, scrollPaneStyle);
128+
widgetTable.align(Align.top);
129+
widgetPane.setScrollingDisabled(true, false);
130+
widgetPane.addListener(new ClickListener() {
131+
@Override
132+
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
133+
stage.setScrollFocus(widgetPane);
134+
}
135+
136+
@Override
137+
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
138+
stage.setScrollFocus(null);
139+
}
140+
});
141+
widgetPane.setFlickScroll(false);
142+
widgetPane.layout();
143+
widgetContainer.add(widgetPane).fill().expand();
144+
widgetContainer.row();
145+
122146
TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
123147
textButtonStyle.font = PathSim.font;
124148
textButtonStyle.up = PathSim.skin.getDrawable("btn_default_normal");
@@ -176,6 +200,7 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
176200
ramsete.setBounds(right+145, Gdx.graphics.getHeight() - 395, 130, 40);
177201

178202
widget = new Label("Manage Paths", lStyle3);
203+
widget.setFontScale(0.65f);
179204

180205
addListeners();
181206

@@ -272,19 +297,24 @@ public void update(float delta) {
272297
if(splineMode && !prevMode && PathSim.pathManager.editingPath()) {
273298
for(Actor a : splineEdit) stage.addActor(a);
274299
for(Actor a : pathEdit) a.remove();
275-
showing = true;
276-
277300
for(Actor a : notPathEdit) stage.addActor(a);
301+
showing = true;
278302
} else if (!splineMode && prevMode && PathSim.pathManager.editingPath()) {
279303
for(Actor a : pathEdit) stage.addActor(a);
280304
for(Actor a : notPathEdit) a.remove();
281-
path.setText("Pause Sim");
282305
for(Actor a : splineEdit) a.remove();
306+
path.setText("Pause Sim");
283307
showing = true;
284308
populatePathEdit();
285309
}
286310

287-
widget.setBounds(PathSim.renderer2d.widgetX + 20, PathSim.renderer2d.widgetY + PathSim.renderer2d.wh - 15 - widget.getPrefHeight()/2, widget.getPrefWidth(), widget.getPrefHeight());
311+
widget.setBounds(PathSim.renderer2d.rwx + 20, PathSim.renderer2d.rwy + PathSim.renderer2d.wh - 20 - widget.getPrefHeight()/2, widget.getPrefWidth(), widget.getPrefHeight());
312+
widgetContainer.setBounds(PathSim.renderer2d.rwx, PathSim.renderer2d.rwy+10, PathSim.renderer2d.ww, PathSim.renderer2d.wh - 55);
313+
if(PathSim.renderer2d.widgetExpanded) {
314+
stage.addActor(widgetContainer);
315+
} else {
316+
widgetContainer.remove();
317+
}
288318

289319
prevEditing = PathSim.pathManager.curEditingPath;
290320
prevMode = splineMode;
@@ -295,6 +325,45 @@ public void update(float delta) {
295325
updateExportFrame(false);
296326
}
297327

328+
public void populateWidget() {
329+
int i = 1;
330+
widgetTable.clear();
331+
for(ExtendedPath p : PathSim.pathManager.paths) {
332+
Label l = new Label("Path " + i, lStyle2);
333+
l.setFontScale(0.5f);
334+
Image del = new Image(PathSim.renderer2d.trash);
335+
del.addListener(new ClickListener() {
336+
public void clicked(InputEvent event, float x, float y){
337+
PathSim.pathManager.delayRemove(p);
338+
}
339+
});
340+
Image edit = new Image(PathSim.renderer2d.edit);
341+
edit.addListener(new ClickListener() {
342+
public void clicked(InputEvent event, float x, float y){
343+
PathSim.pathManager.chooseEditPath(p);
344+
}
345+
});
346+
Image visible = new Image(p.visible ? PathSim.renderer2d.visible : PathSim.renderer2d.invisible);
347+
visible.addListener(new ClickListener() {
348+
public void clicked(InputEvent event, float x, float y){
349+
p.visible = !p.visible;
350+
if(p.visible) visible.setDrawable(new TextureRegionDrawable(PathSim.renderer2d.visible));
351+
else visible.setDrawable(new TextureRegionDrawable(PathSim.renderer2d.invisible));
352+
if(PathSim.pathManager.paths.indexOf(p) == PathSim.pathManager.curEditingPath) {
353+
PathSim.pathManager.curEditingPath = -1;
354+
}
355+
}
356+
});
357+
358+
widgetTable.add(l).height(30).width(140).align(Align.left).pad(0, 15, 0, 0);
359+
widgetTable.add(visible).height(20).width(20).align(Align.right).pad(0, 0, 0, 5);
360+
widgetTable.add(edit).height(20).width(20).align(Align.right).pad(0, 5, 0, 5);
361+
widgetTable.add(del).height(20).width(20).align(Align.right).pad(0, 5, 0, 15);
362+
widgetTable.row();
363+
i++;
364+
}
365+
}
366+
298367
public void populateSplineEdit() {
299368
export.setText("Export Spline");
300369

0 commit comments

Comments
 (0)