forked from agateau/pixelwheels
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugScreen.java
More file actions
241 lines (208 loc) · 8.59 KB
/
Copy pathDebugScreen.java
File metadata and controls
241 lines (208 loc) · 8.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
* Copyright 2017 Aurélien Gâteau <mail@agateau.com>
*
* This file is part of Pixel Wheels.
*
* Tiny Wheels is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.agateau.tinywheels;
import com.agateau.ui.SliderMenuItem;
import com.agateau.ui.Menu;
import com.agateau.ui.RefreshHelper;
import com.agateau.ui.SwitchMenuItem;
import com.agateau.ui.UiBuilder;
import com.agateau.ui.anchor.AnchorGroup;
import com.agateau.utils.FileUtils;
import com.agateau.utils.Introspector;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
/**
* The debug screen
*/
public class DebugScreen extends TwStageScreen {
private final TwGame mGame;
private Menu mMenu;
// This field is set during setupUi: add* methods use it to bind the controls to the correct
// introspector
private Introspector mCurrentIntrospector = null;
public DebugScreen(TwGame game) {
super(game.getAssets().ui);
mGame = game;
new RefreshHelper(getStage()) {
@Override
protected void refresh() {
mGame.replaceScreen(new DebugScreen(mGame));
}
};
setupUi();
}
private void setupUi() {
UiBuilder builder = new UiBuilder(mGame.getAssets().atlas, mGame.getAssets().ui.skin);
AnchorGroup root = (AnchorGroup)builder.build(FileUtils.assets("screens/debug.gdxui"));
root.setFillParent(true);
getStage().addActor(root);
mCurrentIntrospector = mGame.getGamePlayIntrospector();
MenuScrollPane pane = builder.getActor("scrollPane");
mMenu = pane.getMenu();
addTitle("Race");
addRange("Viewport width", "viewportWidth", 20, 800, 10);
addRange("Racer count", "racerCount", 1, 8);
addRange("Max skidmarks", "maxSkidmarks", 10, 200, 10);
addRange("Border restitution", "borderRestitution", 1, 50);
addTitle("Input");
addCheckBox("Force touch input", "alwaysShowTouchInput");
addTitle("Speed");
addRange("Max driving force", "maxDrivingForce", 10, 200, 10);
addRange("Max speed", "maxSpeed", 10, 400, 10);
addTitle("Turbo");
addRange("Strength", "turboStrength", 10, 800, 20);
addRange("Duration", "turboDuration", 0.1f, 2f, 0.1f);
addTitle("Wheels");
addRange("Stickiness", "maxLateralImpulse", 1, 40);
addRange("Steer: low speed", "lowSpeedMaxSteer", 2, 50, 2);
addRange("Steer: high speed", "highSpeedMaxSteer", 2, 50, 1);
addTitle("Vehicle");
addRange("Density", "vehicleDensity", 1, 50);
addRange("Restitution", "vehicleRestitution", 1, 50);
mCurrentIntrospector = mGame.getDebugIntrospector();
addTitle("Debug");
addCheckBox("Show debug hud", "showDebugHud");
addCheckBox("Show debug layer", "showDebugLayer");
addCheckBox("- Draw velocities", "drawVelocities");
addCheckBox("- Draw tile corners", "drawTileCorners");
addCheckBox("Hud debug lines", "showHudDebugLines");
builder.getActor("backButton").addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
onBackPressed();
}
});
}
private void addTitle(String text) {
mMenu.addTitleLabel(text);
}
private void addCheckBox(String text, final String keyName) {
final Introspector introspector = mCurrentIntrospector;
final DebugSwitchMenuItem item = new DebugSwitchMenuItem(mMenu, keyName, introspector);
boolean checked = introspector.get(keyName);
item.setChecked(checked);
mMenu.addItemWithLabel(text, item);
item.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
boolean value = item.isChecked();
introspector.set(keyName, value);
}
});
}
private void addRange(String text, final String keyName, int min, int max) {
addRange(text, keyName, min, max, 1);
}
private void addRange(String text, final String keyName, int min, int max, int stepSize) {
final Introspector introspector = mCurrentIntrospector;
final DebugIntSliderMenuItem item = new DebugIntSliderMenuItem(mMenu, keyName, introspector);
item.setRange(min, max, stepSize);
item.setIntValue(introspector.getInt(keyName));
item.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
int value = item.getIntValue();
introspector.setInt(keyName, value);
item.updateMainActor();
}
});
mMenu.addItemWithLabel(text, item);
}
private void addRange(String text, final String keyName, float min, float max, float stepSize) {
final Introspector introspector = mCurrentIntrospector;
final DebugFloatSliderMenuItem item = new DebugFloatSliderMenuItem(mMenu, keyName, introspector);
item.setRange(min, max, stepSize);
item.setFloatValue(introspector.getFloat(keyName));
item.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
float value = item.getFloatValue();
introspector.setFloat(keyName, value);
item.updateMainActor();
}
});
mMenu.addItemWithLabel(text, item);
}
@Override
public void onBackPressed() {
mGame.getDebugIntrospector().save();
mGame.getGamePlayIntrospector().save();
mGame.popScreen();
}
private class DebugIntSliderMenuItem extends SliderMenuItem {
private final String mKeyName;
private final Introspector mIntrospector;
public DebugIntSliderMenuItem(Menu menu, String keyName, Introspector introspector) {
super(menu);
mKeyName = keyName;
mIntrospector = introspector;
}
@Override
protected String formatValue(int value) {
String text = super.formatValue(value);
int ref = mIntrospector.getReference(mKeyName);
int current = mIntrospector.get(mKeyName);
if (ref != current) {
text += " (" + super.formatValue(ref) + ")";
}
return text;
}
}
private class DebugFloatSliderMenuItem extends SliderMenuItem {
private final String mKeyName;
private final Introspector mIntrospector;
public DebugFloatSliderMenuItem(Menu menu, String keyName, Introspector introspector) {
super(menu);
mKeyName = keyName;
mIntrospector = introspector;
}
@Override
protected String formatValue(int value) {
String text = super.formatValue(value);
float ref = mIntrospector.getReference(mKeyName);
float current = mIntrospector.get(mKeyName);
if (ref != current) {
int intValue = (int)(ref * getDivisor());
text += " (" + super.formatValue(intValue) + ")";
}
return text;
}
}
private class DebugSwitchMenuItem extends SwitchMenuItem {
private final String mKeyName;
private final Introspector mIntrospector;
public DebugSwitchMenuItem(Menu menu, String keyName, Introspector introspector) {
super(menu);
mKeyName = keyName;
mIntrospector = introspector;
}
@Override
protected String formatValue(boolean value) {
String text = super.formatValue(value);
boolean ref = mIntrospector.getReference(mKeyName);
boolean current = mIntrospector.get(mKeyName);
if (ref != current && value == ref) {
text += "*";
}
return text;
}
}
}