23 |
23 |
import android.content.res.Resources;
|
24 |
24 |
|
25 |
25 |
import org.distorted.objectlib.helpers.ObjectStateActioner;
|
26 |
|
import org.distorted.objectlib.helpers.ObjectSurfaceView;
|
27 |
26 |
import org.distorted.objectlib.effects.BaseEffect;
|
28 |
27 |
import org.distorted.objectlib.effects.EffectController;
|
29 |
28 |
import org.distorted.objectlib.effects.scramble.ScrambleEffect;
|
30 |
29 |
import org.distorted.objectlib.helpers.BlockController;
|
31 |
30 |
import org.distorted.objectlib.helpers.MovesFinished;
|
|
31 |
import org.distorted.objectlib.helpers.TwistyActivity;
|
|
32 |
|
|
33 |
import java.lang.ref.WeakReference;
|
32 |
34 |
|
33 |
35 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34 |
36 |
|
35 |
37 |
public class ObjectPreRender implements EffectController
|
36 |
38 |
{
|
37 |
|
private final ObjectSurfaceView mView;
|
|
39 |
private final WeakReference<TwistyActivity> mAct;
|
|
40 |
private final ObjectControl mController;
|
38 |
41 |
private ObjectType mNextObject;
|
39 |
42 |
private TwistyObject mOldObject, mNewObject;
|
40 |
43 |
private SharedPreferences mPreferences;
|
... | ... | |
61 |
64 |
|
62 |
65 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63 |
66 |
|
64 |
|
public ObjectPreRender(ObjectSurfaceView view, ObjectStateActioner actioner)
|
|
67 |
public ObjectPreRender(TwistyActivity act, ObjectControl controller, ObjectStateActioner actioner)
|
65 |
68 |
{
|
66 |
|
mView = view;
|
|
69 |
mAct = new WeakReference<>(act);
|
67 |
70 |
mActioner = actioner;
|
|
71 |
mController = controller;
|
68 |
72 |
|
69 |
73 |
mFinishRotation = false;
|
70 |
74 |
mRemoveRotation = false;
|
... | ... | |
87 |
91 |
|
88 |
92 |
mEffectID = new long[BaseEffect.Type.LENGTH];
|
89 |
93 |
|
90 |
|
mBlockController = new BlockController(mView.getActivity());
|
|
94 |
mBlockController = new BlockController(act);
|
91 |
95 |
unblockEverything();
|
92 |
96 |
}
|
93 |
97 |
|
... | ... | |
99 |
103 |
|
100 |
104 |
if( mOldObject!=null ) mOldObject.releaseResources();
|
101 |
105 |
mOldObject = mNewObject;
|
102 |
|
Resources res = mView.getActivity().getResources();
|
103 |
106 |
|
104 |
|
mNewObject = object.create(mView.getQuat(), moves, res, mScreenWidth);
|
|
107 |
TwistyActivity tact = mAct.get();
|
|
108 |
|
|
109 |
Resources res = tact.getResources();
|
|
110 |
|
|
111 |
mNewObject = object.create( mController.getQuat(), moves, res, mScreenWidth);
|
105 |
112 |
|
106 |
113 |
if( mNewObject!=null )
|
107 |
114 |
{
|
108 |
|
mView.setMovement(mNewObject.getMovement());
|
|
115 |
mController.setMovement(mNewObject.getMovement());
|
109 |
116 |
if( firstTime ) mNewObject.restorePreferences(mPreferences);
|
110 |
117 |
mIsSolved = mNewObject.isSolved();
|
111 |
118 |
}
|
... | ... | |
119 |
126 |
try
|
120 |
127 |
{
|
121 |
128 |
int index = type.ordinal();
|
122 |
|
mEffectID[index] = type.startEffect(mView.getScreen(),this);
|
|
129 |
mEffectID[index] = type.startEffect(mAct.get().getScreen(),this);
|
123 |
130 |
}
|
124 |
131 |
catch( Exception ex )
|
125 |
132 |
{
|
... | ... | |
291 |
298 |
private void setQuatNow()
|
292 |
299 |
{
|
293 |
300 |
mSetQuat = false;
|
294 |
|
mView.setQuat();
|
|
301 |
mController.setQuat();
|
295 |
302 |
}
|
296 |
303 |
|
297 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
298 |
|
// PUBLIC API
|
299 |
304 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
300 |
305 |
|
301 |
|
public void rememberMove(int axis, int row, int angle)
|
|
306 |
void rememberMove(int axis, int row, int angle)
|
302 |
307 |
{
|
303 |
308 |
mDebug += (" (m "+axis+" "+(1<<row)+" "+angle+" "+(System.currentTimeMillis()-mDebugStartTime)+")");
|
304 |
309 |
}
|
305 |
310 |
|
|
311 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
312 |
|
|
313 |
void finishRotation(int nearestAngle)
|
|
314 |
{
|
|
315 |
mNearestAngle = nearestAngle;
|
|
316 |
mFinishRotation = true;
|
|
317 |
}
|
|
318 |
|
|
319 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
320 |
|
|
321 |
void setTextureMap(int cubit, int face, int newColor)
|
|
322 |
{
|
|
323 |
mSetTextureMap = true;
|
|
324 |
|
|
325 |
mCubit = cubit;
|
|
326 |
mFace = face;
|
|
327 |
mNewColor = newColor;
|
|
328 |
}
|
|
329 |
|
|
330 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
331 |
|
|
332 |
void setQuatOnNextRender()
|
|
333 |
{
|
|
334 |
mSetQuat = true;
|
|
335 |
}
|
|
336 |
|
|
337 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
338 |
// INTERNAL API
|
|
339 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
340 |
// this only sets the cubits state to solved
|
|
341 |
|
|
342 |
public void solve()
|
|
343 |
{
|
|
344 |
mSolve = true;
|
|
345 |
}
|
|
346 |
|
|
347 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
348 |
|
|
349 |
public int getNumScrambles()
|
|
350 |
{
|
|
351 |
return mScrambleObjectNum;
|
|
352 |
}
|
|
353 |
|
|
354 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
355 |
|
|
356 |
public TwistyObject getOldObject()
|
|
357 |
{
|
|
358 |
return mOldObject;
|
|
359 |
}
|
|
360 |
|
|
361 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
362 |
// PUBLIC API
|
306 |
363 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
307 |
364 |
|
308 |
365 |
public void setScreenSize(int width)
|
... | ... | |
332 |
389 |
mPreferences = preferences;
|
333 |
390 |
}
|
334 |
391 |
|
335 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
336 |
|
|
337 |
|
public void finishRotation(int nearestAngle)
|
338 |
|
{
|
339 |
|
mNearestAngle = nearestAngle;
|
340 |
|
mFinishRotation = true;
|
341 |
|
}
|
342 |
|
|
343 |
392 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
344 |
393 |
|
345 |
394 |
public void changeObject(ObjectType object)
|
... | ... | |
357 |
406 |
mNextMoves = moves;
|
358 |
407 |
}
|
359 |
408 |
|
360 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
361 |
|
|
362 |
|
public void setTextureMap(int cubit, int face, int newColor)
|
363 |
|
{
|
364 |
|
mSetTextureMap = true;
|
365 |
|
|
366 |
|
mCubit = cubit;
|
367 |
|
mFace = face;
|
368 |
|
mNewColor = newColor;
|
369 |
|
}
|
370 |
|
|
371 |
409 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
372 |
410 |
|
373 |
411 |
public boolean isTouchBlocked()
|
... | ... | |
426 |
464 |
mBlockController.uiUnblocked();
|
427 |
465 |
}
|
428 |
466 |
|
429 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
430 |
|
|
431 |
|
public void setQuatOnNextRender()
|
432 |
|
{
|
433 |
|
mSetQuat = true;
|
434 |
|
}
|
435 |
|
|
436 |
467 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
437 |
468 |
|
438 |
469 |
public void preRender()
|
... | ... | |
502 |
533 |
}
|
503 |
534 |
}
|
504 |
535 |
|
505 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
506 |
|
// this only sets the cubits state to solved
|
507 |
|
|
508 |
|
public void solve()
|
509 |
|
{
|
510 |
|
mSolve = true;
|
511 |
|
}
|
512 |
|
|
513 |
536 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
514 |
537 |
|
515 |
538 |
public void resetAllTextureMaps()
|
... | ... | |
524 |
547 |
return mNewObject;
|
525 |
548 |
}
|
526 |
549 |
|
527 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
528 |
|
|
529 |
|
public TwistyObject getOldObject()
|
530 |
|
{
|
531 |
|
return mOldObject;
|
532 |
|
}
|
533 |
|
|
534 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
535 |
|
|
536 |
|
public int getNumScrambles()
|
537 |
|
{
|
538 |
|
return mScrambleObjectNum;
|
539 |
|
}
|
540 |
|
|
541 |
550 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
542 |
551 |
|
543 |
552 |
public void effectFinished(final long effectID)
|
... | ... | |
560 |
569 |
if( effectID == mEffectID[i] )
|
561 |
570 |
{
|
562 |
571 |
if( i!=BaseEffect.Type.WIN.ordinal() ) unblockEverything();
|
563 |
|
if( i==BaseEffect.Type.SCRAMBLE.ordinal() ) mActioner.onScrambleEffectFinished(mView.getActivity());
|
564 |
|
if( i==BaseEffect.Type.WIN.ordinal() ) mActioner.onWinEffectFinished(mView.getActivity(),mDebug,mScrambleObjectNum);
|
|
572 |
if( i==BaseEffect.Type.SCRAMBLE.ordinal() ) mActioner.onScrambleEffectFinished(mAct.get());
|
|
573 |
if( i==BaseEffect.Type.WIN.ordinal() ) mActioner.onWinEffectFinished(mAct.get(),mDebug,mScrambleObjectNum);
|
565 |
574 |
break;
|
566 |
575 |
}
|
567 |
576 |
}
|
Simplifications