11 |
11 |
|
12 |
12 |
import android.widget.TextView;
|
13 |
13 |
|
|
14 |
import org.distorted.library.effect.PostprocessEffectGlow;
|
|
15 |
import org.distorted.library.main.DistortedEffects;
|
|
16 |
import org.distorted.library.mesh.MeshBase;
|
|
17 |
import org.distorted.library.message.EffectListener;
|
|
18 |
import org.distorted.library.type.Dynamic2D;
|
|
19 |
import org.distorted.library.type.Dynamic4D;
|
|
20 |
import org.distorted.library.type.Static2D;
|
|
21 |
import org.distorted.library.type.Static4D;
|
14 |
22 |
import org.distorted.objectlib.helpers.MovesFinished;
|
15 |
23 |
import org.distorted.objectlib.main.ObjectControl;
|
|
24 |
import org.distorted.objectlib.main.TwistyObject;
|
|
25 |
|
|
26 |
import java.lang.ref.WeakReference;
|
16 |
27 |
|
17 |
28 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
18 |
29 |
|
19 |
|
public class SolverLowerPane implements MovesFinished
|
|
30 |
public class SolverLowerPane implements MovesFinished, EffectListener
|
20 |
31 |
{
|
21 |
32 |
private static final int MOVES_PLACE_0 = 100;
|
22 |
33 |
private static final int MOVES_PLACE_1 = 101;
|
23 |
34 |
private static final int MILLIS_PER_DEGREE = 6;
|
|
35 |
private static final int FLASH_TIME = 1200;
|
24 |
36 |
|
25 |
37 |
private final TextView mText, mPhase;
|
26 |
38 |
private String[] mPhaseNames;
|
27 |
39 |
private int mNumPhases;
|
28 |
40 |
private int[][][] mMoves;
|
29 |
|
private int[][] mCubitsInvolved;
|
|
41 |
private int[][] mCubitsNotInvolved;
|
30 |
42 |
private int mNumMoves,mCurrMove,mCurrPhase;
|
31 |
43 |
private boolean mCanMove;
|
32 |
|
private ObjectControl mControl;
|
|
44 |
|
|
45 |
private final Dynamic2D mHaloAndRadiusDyn;
|
|
46 |
private final Dynamic4D mColorDyn;
|
|
47 |
private final PostprocessEffectGlow mGlow;
|
|
48 |
private final WeakReference<SolverActivity> mAct;
|
|
49 |
private boolean mEffectWorking;
|
33 |
50 |
|
34 |
51 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
35 |
52 |
|
36 |
53 |
SolverLowerPane(SolverActivity act, String[] names)
|
37 |
54 |
{
|
|
55 |
mAct = new WeakReference<>(act);
|
|
56 |
|
38 |
57 |
mText = act.findViewById(R.id.solverText);
|
39 |
58 |
mPhase = act.findViewById(R.id.solverPhaseName);
|
40 |
59 |
|
|
60 |
mHaloAndRadiusDyn = new Dynamic2D(FLASH_TIME,1.0f);
|
|
61 |
mHaloAndRadiusDyn.add(new Static2D( 0, 0));
|
|
62 |
mHaloAndRadiusDyn.add(new Static2D(10,5));
|
|
63 |
|
|
64 |
mColorDyn = new Dynamic4D(FLASH_TIME,1.0f);
|
|
65 |
|
|
66 |
final int[] colors = new int[] {1,1,1}; // white
|
|
67 |
|
|
68 |
Static4D P1 = new Static4D(colors[0],colors[1],colors[2], 0.0f);
|
|
69 |
Static4D P2 = new Static4D(colors[0],colors[1],colors[2], 1.0f);
|
|
70 |
mColorDyn.add(P1);
|
|
71 |
mColorDyn.add(P2);
|
|
72 |
|
|
73 |
mGlow = new PostprocessEffectGlow(mHaloAndRadiusDyn,mColorDyn);
|
|
74 |
|
41 |
75 |
mPhaseNames = names;
|
42 |
76 |
mNumPhases = names.length;
|
43 |
77 |
mMoves = new int[mNumPhases][][];
|
44 |
|
mCubitsInvolved = new int[mNumPhases][];
|
|
78 |
mCubitsNotInvolved = new int[mNumPhases][];
|
45 |
79 |
mCanMove = true;
|
46 |
|
setSolution(act,null,0,null);
|
|
80 |
setSolution(null,0,null);
|
47 |
81 |
}
|
48 |
82 |
|
49 |
83 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50 |
84 |
|
51 |
|
void updateNames(SolverActivity act, String[] names)
|
|
85 |
void updateNames(String[] names)
|
52 |
86 |
{
|
53 |
87 |
mPhaseNames = names;
|
54 |
88 |
mNumPhases = names.length;
|
55 |
89 |
mMoves = new int[mNumPhases][][];
|
56 |
|
mCubitsInvolved = new int[mNumPhases][];
|
|
90 |
mCubitsNotInvolved = new int[mNumPhases][];
|
57 |
91 |
mCanMove = true;
|
58 |
|
setSolution(act,null,0,null);
|
|
92 |
setSolution(null,0,null);
|
59 |
93 |
}
|
60 |
94 |
|
61 |
95 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62 |
96 |
|
63 |
|
void backPhase(SolverActivity act)
|
|
97 |
void backPhase()
|
64 |
98 |
{
|
|
99 |
SolverActivity act = mAct.get();
|
|
100 |
ObjectControl control = act.getControl();
|
|
101 |
|
65 |
102 |
if( mCurrMove>0 )
|
66 |
103 |
{
|
67 |
104 |
int[][] moves = transformMoves(mMoves[mCurrPhase],0,mCurrMove, false);
|
68 |
|
mControl = act.getControl();
|
69 |
|
mControl.applyScrambles(moves);
|
|
105 |
control.applyScrambles(moves);
|
70 |
106 |
mCurrMove = 0;
|
71 |
107 |
}
|
72 |
108 |
else if( mCurrPhase>0 )
|
... | ... | |
74 |
110 |
mCurrPhase--;
|
75 |
111 |
mNumMoves = mMoves[mCurrPhase]==null ? 0 : mMoves[mCurrPhase].length;
|
76 |
112 |
int[][] moves = transformMoves(mMoves[mCurrPhase],0,mNumMoves, false);
|
77 |
|
mControl = act.getControl();
|
78 |
|
mControl.applyScrambles(moves);
|
|
113 |
control.applyScrambles(moves);
|
79 |
114 |
}
|
80 |
115 |
else
|
81 |
116 |
{
|
82 |
117 |
mCurrPhase = mNumPhases-1;
|
83 |
118 |
mNumMoves = mMoves[mCurrPhase]==null ? 0 : mMoves[mCurrPhase].length;
|
84 |
119 |
mCurrMove = mNumMoves;
|
85 |
|
mControl = act.getControl();
|
86 |
120 |
int[][] moves = transformMoves(mMoves, true);
|
87 |
|
mControl.applyScrambles(moves);
|
|
121 |
control.applyScrambles(moves);
|
88 |
122 |
}
|
89 |
123 |
|
90 |
124 |
setText(act);
|
... | ... | |
92 |
126 |
|
93 |
127 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94 |
128 |
|
95 |
|
void nextPhase(SolverActivity act)
|
|
129 |
void nextPhase()
|
96 |
130 |
{
|
|
131 |
SolverActivity act = mAct.get();
|
|
132 |
ObjectControl control = act.getControl();
|
|
133 |
|
97 |
134 |
if( mCurrPhase<mNumPhases-1 )
|
98 |
135 |
{
|
99 |
|
mControl = act.getControl();
|
100 |
|
glowCubits(mControl,mCubitsInvolved[mCurrPhase]);
|
101 |
136 |
int[][] moves = transformMoves(mMoves[mCurrPhase],mCurrMove,mNumMoves, true);
|
102 |
|
mControl.applyScrambles(moves);
|
|
137 |
control.applyScrambles(moves);
|
103 |
138 |
mCurrPhase++;
|
104 |
139 |
mNumMoves = mMoves[mCurrPhase]==null ? 0 : mMoves[mCurrPhase].length;
|
105 |
140 |
mCurrMove = 0;
|
|
141 |
glowCubits(mCubitsNotInvolved[mCurrPhase-1]);
|
106 |
142 |
}
|
107 |
143 |
else if( mCurrMove<mNumMoves )
|
108 |
144 |
{
|
109 |
|
mControl = act.getControl();
|
110 |
|
glowCubits(mControl,mCubitsInvolved[mCurrPhase]);
|
111 |
145 |
int[][] moves = transformMoves(mMoves[mCurrPhase],mCurrMove,mNumMoves, true);
|
112 |
|
mControl.applyScrambles(moves);
|
|
146 |
control.applyScrambles(moves);
|
113 |
147 |
mCurrMove = mNumMoves;
|
|
148 |
glowCubits(mCubitsNotInvolved[mCurrPhase]);
|
114 |
149 |
}
|
115 |
150 |
else
|
116 |
151 |
{
|
117 |
|
mControl = act.getControl();
|
118 |
152 |
mCurrPhase = 0;
|
119 |
153 |
mNumMoves = mMoves[mCurrPhase]==null ? 0 : mMoves[mCurrPhase].length;
|
120 |
154 |
mCurrMove = 0;
|
121 |
155 |
int[][] moves = transformMoves(mMoves, false);
|
122 |
|
mControl.applyScrambles(moves);
|
|
156 |
control.applyScrambles(moves);
|
123 |
157 |
}
|
124 |
158 |
|
125 |
159 |
setText(act);
|
... | ... | |
207 |
241 |
|
208 |
242 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
209 |
243 |
|
210 |
|
private void glowCubits(ObjectControl control, int[] cubits)
|
|
244 |
private void glowCubits(int[] cubits)
|
211 |
245 |
{
|
212 |
|
StringBuilder sb = new StringBuilder();
|
213 |
|
sb.append("Glowing: ");
|
214 |
|
|
215 |
|
for( int c: cubits )
|
|
246 |
if( !mEffectWorking )
|
216 |
247 |
{
|
217 |
|
sb.append(' ');
|
218 |
|
sb.append(c);
|
|
248 |
mEffectWorking = true;
|
|
249 |
SolverActivity act=mAct.get();
|
|
250 |
ObjectControl control = act.getControl();
|
|
251 |
TwistyObject object=control.getObject();
|
|
252 |
DistortedEffects effects=object.getObjectEffects();
|
|
253 |
effects.apply(mGlow);
|
|
254 |
|
|
255 |
MeshBase mesh=object.getObjectMesh();
|
|
256 |
mesh.setComponentsNotAffectedByPostprocessing(cubits);
|
|
257 |
|
|
258 |
mHaloAndRadiusDyn.resetToBeginning();
|
|
259 |
mColorDyn.resetToBeginning();
|
|
260 |
mGlow.notifyWhenFinished(this);
|
219 |
261 |
}
|
220 |
|
|
221 |
|
android.util.Log.e("D", sb.toString() );
|
222 |
262 |
}
|
223 |
263 |
|
224 |
264 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
225 |
265 |
|
226 |
|
private int[] computeCubitsInvolved(int[][] subphases)
|
|
266 |
public void effectFinished(long id)
|
227 |
267 |
{
|
228 |
|
int numCubits = 0;
|
229 |
|
for(int[] sub : subphases) numCubits += (sub==null ? 0 : sub.length);
|
|
268 |
SolverActivity act=mAct.get();
|
|
269 |
ObjectControl control = act.getControl();
|
|
270 |
TwistyObject object=control.getObject();
|
|
271 |
DistortedEffects effects=object.getObjectEffects();
|
|
272 |
effects.abortById(id);
|
230 |
273 |
|
231 |
|
int[] ret = new int[numCubits];
|
232 |
|
int index = 0;
|
|
274 |
mEffectWorking = false;
|
|
275 |
}
|
|
276 |
|
|
277 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
278 |
|
|
279 |
private int[] computeCubitsNotInvolved(int[][] subphases, int numCubits)
|
|
280 |
{
|
|
281 |
int numCubitsInvolved = 0;
|
|
282 |
boolean[] involved = new boolean[numCubits];
|
233 |
283 |
|
234 |
284 |
for(int[] sub : subphases)
|
235 |
285 |
if( sub!=null )
|
236 |
286 |
for(int s : sub)
|
237 |
|
ret[index++] = s;
|
|
287 |
{
|
|
288 |
numCubitsInvolved++;
|
|
289 |
involved[s] = true;
|
|
290 |
}
|
|
291 |
|
|
292 |
int[] ret = new int[numCubits-numCubitsInvolved];
|
|
293 |
int index = 0;
|
|
294 |
|
|
295 |
for(int c=0; c<numCubits; c++)
|
|
296 |
if( !involved[c] ) ret[index++] = c;
|
238 |
297 |
|
239 |
298 |
return ret;
|
240 |
299 |
}
|
241 |
300 |
|
242 |
301 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
243 |
302 |
|
244 |
|
void setSolution(SolverActivity act, int[][] moves, int phase, int[][] subphases)
|
|
303 |
void setSolution(int[][] moves, int phase, int[][] subphases)
|
245 |
304 |
{
|
246 |
|
mCubitsInvolved[phase] = subphases==null ? null : computeCubitsInvolved(subphases);
|
|
305 |
SolverActivity act=mAct.get();
|
|
306 |
|
|
307 |
if( subphases!=null )
|
|
308 |
{
|
|
309 |
ObjectControl control=act.getControl();
|
|
310 |
TwistyObject object=control.getObject();
|
|
311 |
int numCubits=object.getNumCubits();
|
|
312 |
mCubitsNotInvolved[phase]= computeCubitsNotInvolved(subphases, numCubits);
|
|
313 |
}
|
|
314 |
|
247 |
315 |
mMoves[phase] = moves;
|
248 |
316 |
if( phase==0 ) mNumMoves = (moves==null ? 0 : moves.length);
|
249 |
317 |
mCurrPhase = 0;
|
... | ... | |
254 |
322 |
|
255 |
323 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
256 |
324 |
|
257 |
|
void clearMoves(SolverActivity act)
|
|
325 |
void clearMoves()
|
258 |
326 |
{
|
259 |
327 |
for(int p=0; p<mNumPhases; p++) mMoves[p] = null;
|
260 |
328 |
mNumMoves = 0;
|
261 |
329 |
mCurrPhase= 0;
|
262 |
330 |
mCurrMove = 0;
|
263 |
331 |
|
264 |
|
setText(act);
|
|
332 |
setText(mAct.get());
|
265 |
333 |
}
|
266 |
334 |
|
267 |
335 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
268 |
336 |
|
269 |
|
void backMove(SolverActivity act)
|
|
337 |
void backMove()
|
270 |
338 |
{
|
271 |
339 |
if( mMoves!=null && mCanMove )
|
272 |
340 |
{
|
|
341 |
SolverActivity act=mAct.get();
|
|
342 |
|
273 |
343 |
if( mCurrMove>0 )
|
274 |
344 |
{
|
275 |
345 |
mCanMove = false;
|
276 |
346 |
int[] move = mMoves[mCurrPhase][--mCurrMove];
|
277 |
|
mControl = act.getControl();
|
278 |
|
mControl.blockTouch(MOVES_PLACE_0);
|
279 |
|
mControl.addRotation(this, move[0], (1<<move[1]), -move[2], MILLIS_PER_DEGREE);
|
|
347 |
ObjectControl control = act.getControl();
|
|
348 |
control.blockTouch(MOVES_PLACE_0);
|
|
349 |
control.addRotation(this, move[0], (1<<move[1]), -move[2], MILLIS_PER_DEGREE);
|
280 |
350 |
}
|
281 |
351 |
else if( mCurrPhase>0 )
|
282 |
352 |
{
|
... | ... | |
289 |
359 |
mCurrPhase = mNumPhases-1;
|
290 |
360 |
mNumMoves = mMoves[mCurrPhase]==null ? 0 : mMoves[mCurrPhase].length;
|
291 |
361 |
mCurrMove = mNumMoves;
|
292 |
|
mControl = act.getControl();
|
293 |
|
|
294 |
362 |
int[][] moves = transformMoves(mMoves, true);
|
295 |
|
mControl.applyScrambles(moves);
|
|
363 |
ObjectControl control = act.getControl();
|
|
364 |
control.applyScrambles(moves);
|
296 |
365 |
}
|
297 |
366 |
|
298 |
367 |
setText(act);
|
... | ... | |
301 |
370 |
|
302 |
371 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
303 |
372 |
|
304 |
|
void nextMove(SolverActivity act)
|
|
373 |
void nextMove()
|
305 |
374 |
{
|
306 |
375 |
if( mMoves!=null && mCanMove )
|
307 |
376 |
{
|
|
377 |
SolverActivity act=mAct.get();
|
|
378 |
|
308 |
379 |
if( mCurrMove<mNumMoves )
|
309 |
380 |
{
|
310 |
381 |
mCanMove = false;
|
311 |
382 |
int[] move = mMoves[mCurrPhase][mCurrMove++];
|
312 |
|
mControl = act.getControl();
|
313 |
|
mControl.blockTouch(MOVES_PLACE_1);
|
314 |
|
mControl.addRotation(this, move[0], (1<<move[1]), move[2], MILLIS_PER_DEGREE);
|
|
383 |
ObjectControl control = act.getControl();
|
|
384 |
control.blockTouch(MOVES_PLACE_1);
|
|
385 |
control.addRotation(this, move[0], (1<<move[1]), move[2], MILLIS_PER_DEGREE);
|
315 |
386 |
|
316 |
387 |
if( mCurrPhase==mNumPhases-1 && mCurrMove==mNumMoves )
|
317 |
|
glowCubits(mControl,mCubitsInvolved[mCurrPhase]);
|
|
388 |
glowCubits(mCubitsNotInvolved[mCurrPhase]);
|
318 |
389 |
}
|
319 |
390 |
else if( mCurrPhase<mNumPhases-1 )
|
320 |
391 |
{
|
321 |
|
glowCubits(mControl,mCubitsInvolved[mCurrPhase]);
|
|
392 |
glowCubits(mCubitsNotInvolved[mCurrPhase]);
|
322 |
393 |
mCurrPhase++;
|
323 |
394 |
mNumMoves = mMoves[mCurrPhase]==null ? 0 : mMoves[mCurrPhase].length;
|
324 |
395 |
mCurrMove = 0;
|
... | ... | |
329 |
400 |
mNumMoves = mMoves[mCurrPhase]==null ? 0 : mMoves[mCurrPhase].length;
|
330 |
401 |
mCurrMove = 0;
|
331 |
402 |
int[][] moves = transformMoves(mMoves, false);
|
332 |
|
mControl = act.getControl();
|
333 |
|
mControl.applyScrambles(moves);
|
|
403 |
ObjectControl control = act.getControl();
|
|
404 |
control.applyScrambles(moves);
|
334 |
405 |
}
|
335 |
406 |
|
336 |
407 |
setText(act);
|
... | ... | |
342 |
413 |
public void onActionFinished(final long effectID)
|
343 |
414 |
{
|
344 |
415 |
mCanMove = true;
|
345 |
|
mControl.unblockRotation();
|
|
416 |
|
|
417 |
SolverActivity act=mAct.get();
|
|
418 |
ObjectControl control = act.getControl();
|
|
419 |
control.unblockRotation();
|
346 |
420 |
}
|
347 |
421 |
}
|
Glow cubits involved in the phase.