Revision f5da732a
Added by Leszek Koltunski over 4 years ago
| src/main/java/org/distorted/control/RubikControl.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2021 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.control; |
|
| 21 |
|
|
| 22 |
import org.distorted.library.message.EffectListener; |
|
| 23 |
import org.distorted.main.RubikActivity; |
|
| 24 |
|
|
| 25 |
import java.lang.ref.WeakReference; |
|
| 26 |
|
|
| 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 28 |
|
|
| 29 |
public class RubikControl implements EffectListener, Runnable |
|
| 30 |
{
|
|
| 31 |
WeakReference<RubikActivity> mRefAct; |
|
| 32 |
long mWholeID, mRotateID; |
|
| 33 |
boolean mWholeReturned, mRotateReturned; |
|
| 34 |
|
|
| 35 |
long mRetID; |
|
| 36 |
|
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
|
|
| 39 |
private void addWholeObjects() |
|
| 40 |
{
|
|
| 41 |
mWholeID = 0; |
|
| 42 |
|
|
| 43 |
mRetID = mWholeID; |
|
| 44 |
|
|
| 45 |
Thread networkThrd = new Thread(this); |
|
| 46 |
networkThrd.start(); |
|
| 47 |
} |
|
| 48 |
|
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
|
|
| 51 |
private void addWholeEffects() |
|
| 52 |
{
|
|
| 53 |
|
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 57 |
|
|
| 58 |
private void removeWholeObjects() |
|
| 59 |
{
|
|
| 60 |
|
|
| 61 |
} |
|
| 62 |
|
|
| 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 64 |
|
|
| 65 |
private void addRotateObjects() |
|
| 66 |
{
|
|
| 67 |
mRotateID = 1; |
|
| 68 |
|
|
| 69 |
mRetID = mRotateID; |
|
| 70 |
|
|
| 71 |
Thread networkThrd = new Thread(this); |
|
| 72 |
networkThrd.start(); |
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
|
|
| 77 |
private void addRotateEffects() |
|
| 78 |
{
|
|
| 79 |
|
|
| 80 |
} |
|
| 81 |
|
|
| 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 83 |
|
|
| 84 |
private void removeRotateObjects() |
|
| 85 |
{
|
|
| 86 |
|
|
| 87 |
} |
|
| 88 |
|
|
| 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 90 |
|
|
| 91 |
private void animateCubeWhole() |
|
| 92 |
{
|
|
| 93 |
addWholeObjects(); |
|
| 94 |
addWholeEffects(); |
|
| 95 |
} |
|
| 96 |
|
|
| 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 98 |
|
|
| 99 |
private void finishWhole() |
|
| 100 |
{
|
|
| 101 |
removeWholeObjects(); |
|
| 102 |
|
|
| 103 |
mWholeReturned = true; |
|
| 104 |
|
|
| 105 |
if( !mRotateReturned ) animateCubeRotate(); |
|
| 106 |
} |
|
| 107 |
|
|
| 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 109 |
|
|
| 110 |
private void animateCubeRotate() |
|
| 111 |
{
|
|
| 112 |
addRotateObjects(); |
|
| 113 |
addRotateEffects(); |
|
| 114 |
} |
|
| 115 |
|
|
| 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 117 |
|
|
| 118 |
private void finishRotate() |
|
| 119 |
{
|
|
| 120 |
removeRotateObjects(); |
|
| 121 |
|
|
| 122 |
mRotateReturned= true; |
|
| 123 |
|
|
| 124 |
RubikActivity act = mRefAct.get(); |
|
| 125 |
if( act!=null ) act.unblockEverything(); |
|
| 126 |
} |
|
| 127 |
|
|
| 128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 129 |
// PUBLIC |
|
| 130 |
|
|
| 131 |
@Override |
|
| 132 |
public void run() |
|
| 133 |
{
|
|
| 134 |
android.util.Log.e("D", "running...");
|
|
| 135 |
|
|
| 136 |
try |
|
| 137 |
{
|
|
| 138 |
Thread.sleep(4000); |
|
| 139 |
} |
|
| 140 |
catch(InterruptedException ex) |
|
| 141 |
{
|
|
| 142 |
// ignore |
|
| 143 |
} |
|
| 144 |
|
|
| 145 |
android.util.Log.e("D", "end running...");
|
|
| 146 |
|
|
| 147 |
effectFinished(mRetID); |
|
| 148 |
} |
|
| 149 |
|
|
| 150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 151 |
|
|
| 152 |
public void effectFinished(long effectID) |
|
| 153 |
{
|
|
| 154 |
if( effectID==mWholeID ) finishWhole(); |
|
| 155 |
if( effectID==mRotateID ) finishRotate(); |
|
| 156 |
} |
|
| 157 |
|
|
| 158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 159 |
|
|
| 160 |
public void animateAll(RubikActivity act) |
|
| 161 |
{
|
|
| 162 |
act.blockEverything(); |
|
| 163 |
mRefAct = new WeakReference<>(act); |
|
| 164 |
|
|
| 165 |
mWholeReturned = false; |
|
| 166 |
mRotateReturned= false; |
|
| 167 |
|
|
| 168 |
animateCubeWhole(); |
|
| 169 |
} |
|
| 170 |
|
|
| 171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 172 |
|
|
| 173 |
public void animateRotate(RubikActivity act) |
|
| 174 |
{
|
|
| 175 |
act.blockEverything(); |
|
| 176 |
mRefAct = new WeakReference<>(act); |
|
| 177 |
|
|
| 178 |
mWholeReturned = true; |
|
| 179 |
mRotateReturned= false; |
|
| 180 |
|
|
| 181 |
animateCubeRotate(); |
|
| 182 |
} |
|
| 183 |
} |
|
| src/main/java/org/distorted/dialogs/RubikDialogNewRecord.java | ||
|---|---|---|
| 75 | 75 |
RubikScores scores = RubikScores.getInstance(); |
| 76 | 76 |
String name = scores.getName(); |
| 77 | 77 |
Bundle bundle = new Bundle(); |
| 78 |
ScreenList.switchState(act, ScreenList.PLAY);
|
|
| 78 |
ScreenList.switchScreen(act, ScreenList.PLAY);
|
|
| 79 | 79 |
|
| 80 | 80 |
if( name.length()>0 ) |
| 81 | 81 |
{
|
| 82 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
|
|
| 82 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
| 83 | 83 |
int object = play.getObject(); |
| 84 | 84 |
int size = play.getSize(); |
| 85 | 85 |
int sizeIndex = ObjectList.getSizeIndex(object,size); |
| ... | ... | |
| 108 | 108 |
public void onClick(DialogInterface dialog, int which) |
| 109 | 109 |
{
|
| 110 | 110 |
RubikActivity act = (RubikActivity)getActivity(); |
| 111 |
ScreenList.switchState(act, ScreenList.PLAY);
|
|
| 111 |
ScreenList.switchScreen(act, ScreenList.PLAY);
|
|
| 112 | 112 |
} |
| 113 | 113 |
}); |
| 114 | 114 |
|
| src/main/java/org/distorted/dialogs/RubikDialogPatternView.java | ||
|---|---|---|
| 98 | 98 |
|
| 99 | 99 |
ract.setupObject(list, size, moves); |
| 100 | 100 |
|
| 101 |
ScreenList.switchState(ract, ScreenList.PATT);
|
|
| 102 |
RubikScreenPattern state = (RubikScreenPattern) ScreenList.PATT.getStateClass();
|
|
| 101 |
ScreenList.switchScreen(ract, ScreenList.PATT);
|
|
| 102 |
RubikScreenPattern state = (RubikScreenPattern) ScreenList.PATT.getScreenClass();
|
|
| 103 | 103 |
state.setPattern(ract, mTab, groupPosition, childPosition); |
| 104 | 104 |
|
| 105 | 105 |
mDialog.rememberState(); |
| src/main/java/org/distorted/dialogs/RubikDialogSetName.java | ||
|---|---|---|
| 144 | 144 |
name = name.replace(' ', '_');
|
| 145 | 145 |
|
| 146 | 146 |
RubikActivity act = (RubikActivity)getActivity(); |
| 147 |
ScreenList.switchState(act, ScreenList.PLAY);
|
|
| 147 |
ScreenList.switchScreen(act, ScreenList.PLAY);
|
|
| 148 | 148 |
RubikScores.getInstance().setName(name); |
| 149 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
|
|
| 149 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
| 150 | 150 |
|
| 151 | 151 |
int object = play.getObject(); |
| 152 | 152 |
int size = play.getSize(); |
| src/main/java/org/distorted/dialogs/RubikDialogSolved.java | ||
|---|---|---|
| 69 | 69 |
public void onClick(DialogInterface dialog, int which) |
| 70 | 70 |
{
|
| 71 | 71 |
RubikActivity act = (RubikActivity)getActivity(); |
| 72 |
ScreenList.switchState(act, ScreenList.PLAY);
|
|
| 72 |
ScreenList.switchScreen(act, ScreenList.PLAY);
|
|
| 73 | 73 |
} |
| 74 | 74 |
}); |
| 75 | 75 |
|
| src/main/java/org/distorted/main/RubikActivity.java | ||
|---|---|---|
| 87 | 87 |
private static int mScreenWidth, mScreenHeight; |
| 88 | 88 |
private boolean mPolicyAccepted, mIsChinese; |
| 89 | 89 |
private int mCurrentApiVersion; |
| 90 |
private boolean mIsLocked; |
|
| 90 |
private boolean mIsLocked, mRemLocked;
|
|
| 91 | 91 |
|
| 92 | 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 93 | 93 |
|
| ... | ... | |
| 242 | 242 |
view.onResume(); |
| 243 | 243 |
view.initialize(); |
| 244 | 244 |
restorePreferences(); |
| 245 |
ScreenList.setState(this);
|
|
| 245 |
ScreenList.setScreen(this);
|
|
| 246 | 246 |
|
| 247 | 247 |
if( mJustStarted ) |
| 248 | 248 |
{
|
| ... | ... | |
| 253 | 253 |
} |
| 254 | 254 |
|
| 255 | 255 |
boolean success = false; |
| 256 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
|
|
| 256 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
| 257 | 257 |
int object = play.getObject(); |
| 258 | 258 |
int size = play.getSize(); |
| 259 | 259 |
|
| ... | ... | |
| 307 | 307 |
|
| 308 | 308 |
for (int i = 0; i< ScreenList.LENGTH; i++) |
| 309 | 309 |
{
|
| 310 |
ScreenList.getState(i).getStateClass().savePreferences(editor);
|
|
| 310 |
ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
|
|
| 311 | 311 |
} |
| 312 | 312 |
|
| 313 | 313 |
ScreenList.savePreferences(editor); |
| ... | ... | |
| 332 | 332 |
|
| 333 | 333 |
for (int i = 0; i< ScreenList.LENGTH; i++) |
| 334 | 334 |
{
|
| 335 |
ScreenList.getState(i).getStateClass().restorePreferences(preferences);
|
|
| 335 |
ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
|
|
| 336 | 336 |
} |
| 337 | 337 |
|
| 338 | 338 |
ScreenList.restorePreferences(preferences); |
| ... | ... | |
| 545 | 545 |
|
| 546 | 546 |
public boolean isLocked() |
| 547 | 547 |
{
|
| 548 |
ScreenList state = ScreenList.getCurrentState();
|
|
| 548 |
ScreenList state = ScreenList.getCurrentScreen();
|
|
| 549 | 549 |
|
| 550 | 550 |
if( state== ScreenList.PLAY || state== ScreenList.READ || state== ScreenList.SOLV ) |
| 551 | 551 |
{
|
| ... | ... | |
| 555 | 555 |
return false; |
| 556 | 556 |
} |
| 557 | 557 |
|
| 558 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 559 |
|
|
| 560 |
public void blockEverything() |
|
| 561 |
{
|
|
| 562 |
mRemLocked = mIsLocked; |
|
| 563 |
mIsLocked = true; |
|
| 564 |
|
|
| 565 |
RubikPreRender pre = getPreRender(); |
|
| 566 |
pre.blockEverything(); |
|
| 567 |
} |
|
| 568 |
|
|
| 569 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 570 |
|
|
| 571 |
public void unblockEverything() |
|
| 572 |
{
|
|
| 573 |
mIsLocked = mRemLocked; |
|
| 574 |
|
|
| 575 |
RubikPreRender pre = getPreRender(); |
|
| 576 |
pre.unblockEverything(); |
|
| 577 |
} |
|
| 578 |
|
|
| 558 | 579 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 559 | 580 |
|
| 560 | 581 |
public boolean retLocked() |
| src/main/java/org/distorted/main/RubikPreRender.java | ||
|---|---|---|
| 172 | 172 |
|
| 173 | 173 |
if( solved && !mIsSolved ) |
| 174 | 174 |
{
|
| 175 |
if( ScreenList.getCurrentState()== ScreenList.SOLV )
|
|
| 175 |
if( ScreenList.getCurrentScreen()== ScreenList.SOLV )
|
|
| 176 | 176 |
{
|
| 177 |
RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getStateClass();
|
|
| 177 |
RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getScreenClass();
|
|
| 178 | 178 |
mNewRecord = solving.getRecord(); |
| 179 | 179 |
|
| 180 | 180 |
if( mNewRecord< 0 ) |
| ... | ... | |
| 349 | 349 |
|
| 350 | 350 |
private void reportRecord() |
| 351 | 351 |
{
|
| 352 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
|
|
| 352 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
| 353 | 353 |
RubikScores scores = RubikScores.getInstance(); |
| 354 | 354 |
|
| 355 | 355 |
int object = play.getObject(); |
| ... | ... | |
| 556 | 556 |
return mCanPlay; |
| 557 | 557 |
} |
| 558 | 558 |
|
| 559 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 560 |
|
|
| 561 |
public void blockEverything() |
|
| 562 |
{
|
|
| 563 |
mCanRotate = false; |
|
| 564 |
mCanPlay = false; |
|
| 565 |
} |
|
| 566 |
|
|
| 567 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 568 |
|
|
| 569 |
public void unblockEverything() |
|
| 570 |
{
|
|
| 571 |
mCanRotate = true; |
|
| 572 |
mCanPlay = true; |
|
| 573 |
} |
|
| 574 |
|
|
| 559 | 575 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 560 | 576 |
|
| 561 | 577 |
void setQuatOnNextRender() |
| ... | ... | |
| 693 | 709 |
@Override |
| 694 | 710 |
public void run() |
| 695 | 711 |
{
|
| 696 |
ScreenList.switchState( act, ScreenList.READ);
|
|
| 712 |
ScreenList.switchScreen( act, ScreenList.READ);
|
|
| 697 | 713 |
} |
| 698 | 714 |
}); |
| 699 | 715 |
} |
| 700 | 716 |
|
| 701 | 717 |
if( i==BaseEffect.Type.WIN.ordinal() ) |
| 702 | 718 |
{
|
| 703 |
if( ScreenList.getCurrentState()== ScreenList.SOLV )
|
|
| 719 |
if( ScreenList.getCurrentScreen()== ScreenList.SOLV )
|
|
| 704 | 720 |
{
|
| 705 | 721 |
final RubikActivity act = (RubikActivity)mView.getContext(); |
| 706 | 722 |
Bundle bundle = new Bundle(); |
| ... | ... | |
| 727 | 743 |
@Override |
| 728 | 744 |
public void run() |
| 729 | 745 |
{
|
| 730 |
ScreenList.switchState( act, ScreenList.DONE);
|
|
| 746 |
ScreenList.switchScreen( act, ScreenList.DONE);
|
|
| 731 | 747 |
} |
| 732 | 748 |
}); |
| 733 | 749 |
} |
| src/main/java/org/distorted/main/RubikSurfaceView.java | ||
|---|---|---|
| 327 | 327 |
|
| 328 | 328 |
if( down ) |
| 329 | 329 |
{
|
| 330 |
RubikScreenSolver solver = (RubikScreenSolver) ScreenList.SVER.getStateClass();
|
|
| 330 |
RubikScreenSolver solver = (RubikScreenSolver) ScreenList.SVER.getScreenClass();
|
|
| 331 | 331 |
mLastCubitFace = mMovement.getTouchedFace(); |
| 332 | 332 |
float[] point = mMovement.getTouchedPoint3D(); |
| 333 | 333 |
int color = solver.getCurrentColor(); |
| ... | ... | |
| 416 | 416 |
|
| 417 | 417 |
if( angle!=0 ) |
| 418 | 418 |
{
|
| 419 |
if( ScreenList.getCurrentState()== ScreenList.SOLV )
|
|
| 419 |
if( ScreenList.getCurrentScreen()== ScreenList.SOLV )
|
|
| 420 | 420 |
{
|
| 421 |
RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getStateClass();
|
|
| 421 |
RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getScreenClass();
|
|
| 422 | 422 |
solving.addMove(mCurrentAxis, mCurrentRow, angle); |
| 423 | 423 |
} |
| 424 |
if( ScreenList.getCurrentState()== ScreenList.PLAY )
|
|
| 424 |
if( ScreenList.getCurrentScreen()== ScreenList.PLAY )
|
|
| 425 | 425 |
{
|
| 426 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
|
|
| 426 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
| 427 | 427 |
play.addMove(mCurrentAxis, mCurrentRow, angle); |
| 428 | 428 |
} |
| 429 | 429 |
} |
| ... | ... | |
| 477 | 477 |
|
| 478 | 478 |
object.beginNewRotation( mCurrentAxis, mCurrentRow ); |
| 479 | 479 |
|
| 480 |
if( ScreenList.getCurrentState()== ScreenList.READ )
|
|
| 480 |
if( ScreenList.getCurrentScreen()== ScreenList.READ )
|
|
| 481 | 481 |
{
|
| 482 |
RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getStateClass();
|
|
| 482 |
RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getScreenClass();
|
|
| 483 | 483 |
solving.resetElapsed(); |
| 484 | 484 |
|
| 485 | 485 |
final RubikActivity act = (RubikActivity)getContext(); |
| ... | ... | |
| 489 | 489 |
@Override |
| 490 | 490 |
public void run() |
| 491 | 491 |
{
|
| 492 |
ScreenList.switchState( act, ScreenList.SOLV);
|
|
| 492 |
ScreenList.switchScreen( act, ScreenList.SOLV);
|
|
| 493 | 493 |
} |
| 494 | 494 |
}); |
| 495 | 495 |
} |
| src/main/java/org/distorted/screens/RubikScreenAbstract.java | ||
|---|---|---|
| 32 | 32 |
{
|
| 33 | 33 |
int getPatternOrdinal() |
| 34 | 34 |
{
|
| 35 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
|
|
| 35 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
| 36 | 36 |
int obj = play.getObject(); |
| 37 | 37 |
int size = play.getSize(); |
| 38 | 38 |
int ret = RubikPatternList.getOrdinal(obj,size); |
| ... | ... | |
| 49 | 49 |
|
| 50 | 50 |
int getTutorialOrdinal() |
| 51 | 51 |
{
|
| 52 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
|
|
| 52 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
| 53 | 53 |
int obj = play.getObject(); |
| 54 | 54 |
int size = play.getSize(); |
| 55 | 55 |
|
| ... | ... | |
| 65 | 65 |
|
| 66 | 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 67 | 67 |
|
| 68 |
abstract void enterState(RubikActivity act);
|
|
| 69 |
abstract void leaveState(RubikActivity act);
|
|
| 68 |
abstract void enterScreen(RubikActivity act);
|
|
| 69 |
abstract void leaveScreen(RubikActivity act);
|
|
| 70 | 70 |
public abstract void savePreferences(SharedPreferences.Editor editor); |
| 71 | 71 |
public abstract void restorePreferences(SharedPreferences preferences); |
| 72 | 72 |
} |
| src/main/java/org/distorted/screens/RubikScreenDone.java | ||
|---|---|---|
| 42 | 42 |
|
| 43 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 44 | 44 |
|
| 45 |
void leaveState(RubikActivity act)
|
|
| 45 |
void leaveScreen(RubikActivity act)
|
|
| 46 | 46 |
{
|
| 47 | 47 |
|
| 48 | 48 |
} |
| 49 | 49 |
|
| 50 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 51 | 51 |
|
| 52 |
void enterState(final RubikActivity act)
|
|
| 52 |
void enterScreen(final RubikActivity act)
|
|
| 53 | 53 |
{
|
| 54 | 54 |
float width = act.getScreenWidthInPixels(); |
| 55 | 55 |
float titleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
| src/main/java/org/distorted/screens/RubikScreenPattern.java | ||
|---|---|---|
| 58 | 58 |
|
| 59 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 60 | 60 |
|
| 61 |
void leaveState(RubikActivity act)
|
|
| 61 |
void leaveScreen(RubikActivity act)
|
|
| 62 | 62 |
{
|
| 63 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
|
|
| 63 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
| 64 | 64 |
|
| 65 | 65 |
ObjectList object = RubikPatternList.getObject(mPatternOrdinal); |
| 66 | 66 |
int size = RubikPatternList.getSize(mPatternOrdinal); |
| ... | ... | |
| 76 | 76 |
|
| 77 | 77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 78 | 78 |
|
| 79 |
void enterState(final RubikActivity act)
|
|
| 79 |
void enterScreen(final RubikActivity act)
|
|
| 80 | 80 |
{
|
| 81 | 81 |
float width = act.getScreenWidthInPixels(); |
| 82 | 82 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
| src/main/java/org/distorted/screens/RubikScreenPlay.java | ||
|---|---|---|
| 33 | 33 |
import android.widget.LinearLayout; |
| 34 | 34 |
import android.widget.PopupWindow; |
| 35 | 35 |
|
| 36 |
import org.distorted.control.RubikControl; |
|
| 36 | 37 |
import org.distorted.dialogs.RubikDialogAbout; |
| 37 | 38 |
import org.distorted.dialogs.RubikDialogPattern; |
| 38 | 39 |
import org.distorted.dialogs.RubikDialogScores; |
| ... | ... | |
| 71 | 72 |
private float mButtonSize, mMenuItemSize, mMenuTextSize; |
| 72 | 73 |
private int mColCount, mRowCount; |
| 73 | 74 |
private LinearLayout mPlayLayout; |
| 75 |
private RubikControl mControlWhole; |
|
| 74 | 76 |
|
| 75 | 77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 76 | 78 |
|
| 77 |
void leaveState(RubikActivity act)
|
|
| 79 |
void leaveScreen(RubikActivity act)
|
|
| 78 | 80 |
{
|
| 79 | 81 |
|
| 80 | 82 |
} |
| 81 | 83 |
|
| 82 | 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 83 | 85 |
|
| 84 |
void enterState(final RubikActivity act)
|
|
| 86 |
void enterScreen(final RubikActivity act)
|
|
| 85 | 87 |
{
|
| 86 | 88 |
float width = act.getScreenWidthInPixels(); |
| 87 | 89 |
|
| ... | ... | |
| 285 | 287 |
@Override |
| 286 | 288 |
public void onClick(View v) |
| 287 | 289 |
{
|
| 288 |
if( act.getPreRender().canPlay() && ScreenList.getCurrentState()== ScreenList.PLAY )
|
|
| 290 |
if( act.getPreRender().canPlay() && ScreenList.getCurrentScreen()== ScreenList.PLAY )
|
|
| 289 | 291 |
{
|
| 290 | 292 |
mObject = obj; |
| 291 | 293 |
mSize = sizes[index]; |
| ... | ... | |
| 369 | 371 |
adjustLevels(act); |
| 370 | 372 |
} |
| 371 | 373 |
|
| 372 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 373 |
|
|
| 374 |
private void controlTheCube() |
|
| 375 |
{
|
|
| 376 |
android.util.Log.e("D", "Control");
|
|
| 377 |
} |
|
| 378 |
|
|
| 379 | 374 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 380 | 375 |
|
| 381 | 376 |
private void MenuAction(RubikActivity act, int button) |
| 382 | 377 |
{
|
| 383 | 378 |
switch(button) |
| 384 | 379 |
{
|
| 385 |
case 0: RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
|
|
| 380 |
case 0: RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
| 386 | 381 |
int object = play.getObject(); |
| 387 | 382 |
int size = play.getSize(); |
| 388 | 383 |
int sizeIndex = ObjectList.getSizeIndex(object,size); |
| ... | ... | |
| 400 | 395 |
pDiag.setArguments(pBundle); |
| 401 | 396 |
pDiag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() ); |
| 402 | 397 |
break; |
| 403 |
case 2: controlTheCube(); |
|
| 398 |
case 2: if( mControlWhole==null ) mControlWhole = new RubikControl(); |
|
| 399 |
mControlWhole.animateAll(act); |
|
| 404 | 400 |
break; |
| 405 |
case 3: ScreenList.switchState(act, ScreenList.SVER);
|
|
| 401 |
case 3: ScreenList.switchScreen(act, ScreenList.SVER);
|
|
| 406 | 402 |
break; |
| 407 | 403 |
case 4: RubikDialogTutorial tDiag = new RubikDialogTutorial(); |
| 408 | 404 |
Bundle tBundle = new Bundle(); |
| src/main/java/org/distorted/screens/RubikScreenReady.java | ||
|---|---|---|
| 38 | 38 |
|
| 39 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 40 | 40 |
|
| 41 |
void leaveState(RubikActivity act)
|
|
| 41 |
void leaveScreen(RubikActivity act)
|
|
| 42 | 42 |
{
|
| 43 | 43 |
|
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 47 | 47 |
|
| 48 |
void enterState(final RubikActivity act)
|
|
| 48 |
void enterScreen(final RubikActivity act)
|
|
| 49 | 49 |
{
|
| 50 | 50 |
float width = act.getScreenWidthInPixels(); |
| 51 | 51 |
float titleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
| src/main/java/org/distorted/screens/RubikScreenSolution.java | ||
|---|---|---|
| 49 | 49 |
|
| 50 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 51 | 51 |
|
| 52 |
void leaveState(RubikActivity act)
|
|
| 52 |
void leaveScreen(RubikActivity act)
|
|
| 53 | 53 |
{
|
| 54 | 54 |
TwistyObject object = act.getObject(); |
| 55 | 55 |
object.solve(); |
| ... | ... | |
| 57 | 57 |
|
| 58 | 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 59 | 59 |
|
| 60 |
void enterState(final RubikActivity act)
|
|
| 60 |
void enterScreen(final RubikActivity act)
|
|
| 61 | 61 |
{
|
| 62 | 62 |
float width = act.getScreenWidthInPixels(); |
| 63 | 63 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
| src/main/java/org/distorted/screens/RubikScreenSolver.java | ||
|---|---|---|
| 62 | 62 |
|
| 63 | 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 64 | 64 |
|
| 65 |
void leaveState(RubikActivity act)
|
|
| 65 |
void leaveScreen(RubikActivity act)
|
|
| 66 | 66 |
{
|
| 67 | 67 |
|
| 68 | 68 |
} |
| 69 | 69 |
|
| 70 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 71 | 71 |
|
| 72 |
void enterState(final RubikActivity act)
|
|
| 72 |
void enterScreen(final RubikActivity act)
|
|
| 73 | 73 |
{
|
| 74 | 74 |
float width = act.getScreenWidthInPixels(); |
| 75 | 75 |
float heigh = act.getScreenHeightInPixels(); |
| ... | ... | |
| 87 | 87 |
mCurrentObjectSize = ImplementedSolversList.getObjectSize(0); |
| 88 | 88 |
|
| 89 | 89 |
act.setupObject(mCurrentObject, mCurrentObjectSize, null); |
| 90 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
|
|
| 90 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
| 91 | 91 |
play.setObjectAndSize(act, mCurrentObject, mCurrentObjectSize); |
| 92 | 92 |
|
| 93 | 93 |
mFaceColors = ObjectList.retFaceColors(mCurrentObject); |
| ... | ... | |
| 292 | 292 |
@Override |
| 293 | 293 |
public void run() |
| 294 | 294 |
{
|
| 295 |
ScreenList.switchState(act, ScreenList.SOLU);
|
|
| 296 |
RubikScreenSolution solution = (RubikScreenSolution) ScreenList.SOLU.getStateClass();
|
|
| 295 |
ScreenList.switchScreen(act, ScreenList.SOLU);
|
|
| 296 |
RubikScreenSolution solution = (RubikScreenSolution) ScreenList.SOLU.getScreenClass();
|
|
| 297 | 297 |
solution.setupMoves(act, moves); |
| 298 | 298 |
} |
| 299 | 299 |
}); |
| src/main/java/org/distorted/screens/RubikScreenSolving.java | ||
|---|---|---|
| 56 | 56 |
|
| 57 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 58 | 58 |
|
| 59 |
void leaveState(RubikActivity act)
|
|
| 59 |
void leaveScreen(RubikActivity act)
|
|
| 60 | 60 |
{
|
| 61 | 61 |
stopCounting(); |
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 65 | 65 |
|
| 66 |
void enterState(final RubikActivity act)
|
|
| 66 |
void enterScreen(final RubikActivity act)
|
|
| 67 | 67 |
{
|
| 68 | 68 |
float width = act.getScreenWidthInPixels(); |
| 69 | 69 |
float titleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
| ... | ... | |
| 171 | 171 |
|
| 172 | 172 |
mElapsed = System.currentTimeMillis()-mStartTime; |
| 173 | 173 |
|
| 174 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
|
|
| 174 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
| 175 | 175 |
int object = play.getObject(); |
| 176 | 176 |
int size = play.getSize(); |
| 177 | 177 |
int level = play.getLevel(); |
| src/main/java/org/distorted/screens/ScreenList.java | ||
|---|---|---|
| 41 | 41 |
; |
| 42 | 42 |
|
| 43 | 43 |
public static final int LENGTH = values().length; |
| 44 |
private static final ScreenList[] screens; |
|
| 44 | 45 |
private final ScreenList mBack; |
| 45 |
private int mMode; |
|
| 46 |
private final int mMode;
|
|
| 46 | 47 |
private final RubikScreenAbstract mClass; |
| 47 |
private static final ScreenList[] states; |
|
| 48 | 48 |
|
| 49 |
private static ScreenList mCurrState;
|
|
| 49 |
private static ScreenList mCurrScreen;
|
|
| 50 | 50 |
|
| 51 | 51 |
static |
| 52 | 52 |
{
|
| 53 | 53 |
int i = 0; |
| 54 |
states = new ScreenList[LENGTH]; |
|
| 55 |
|
|
| 56 |
for(ScreenList state: ScreenList.values()) |
|
| 57 |
{
|
|
| 58 |
states[i] = state; |
|
| 59 |
i++; |
|
| 60 |
} |
|
| 54 |
screens = new ScreenList[LENGTH]; |
|
| 55 |
for(ScreenList state: ScreenList.values()) screens[i++] = state; |
|
| 61 | 56 |
} |
| 62 | 57 |
|
| 63 | 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 64 | 59 |
|
| 65 |
public static ScreenList getState(int ordinal)
|
|
| 60 |
public static ScreenList getScreen(int ordinal)
|
|
| 66 | 61 |
{
|
| 67 |
return ordinal>=0 && ordinal<LENGTH ? states[ordinal] : PLAY;
|
|
| 62 |
return ordinal>=0 && ordinal<LENGTH ? screens[ordinal] : PLAY;
|
|
| 68 | 63 |
} |
| 69 | 64 |
|
| 70 | 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 71 | 66 |
|
| 72 |
public static ScreenList getStateFromName(String name)
|
|
| 67 |
public static ScreenList getScreenFromName(String name)
|
|
| 73 | 68 |
{
|
| 74 | 69 |
for(int i=0; i<LENGTH; i++) |
| 75 | 70 |
{
|
| 76 |
if( name.equals(states[i].name()) )
|
|
| 71 |
if( name.equals(screens[i].name()) )
|
|
| 77 | 72 |
{
|
| 78 |
return states[i];
|
|
| 73 |
return screens[i];
|
|
| 79 | 74 |
} |
| 80 | 75 |
} |
| 81 | 76 |
|
| ... | ... | |
| 84 | 79 |
|
| 85 | 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 86 | 81 |
|
| 87 |
public static ScreenList getCurrentState()
|
|
| 82 |
public static ScreenList getCurrentScreen()
|
|
| 88 | 83 |
{
|
| 89 |
return mCurrState;
|
|
| 84 |
return mCurrScreen;
|
|
| 90 | 85 |
} |
| 91 | 86 |
|
| 92 | 87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 93 | 88 |
|
| 94 | 89 |
public static int getMode() |
| 95 | 90 |
{
|
| 96 |
return mCurrState.mMode;
|
|
| 91 |
return mCurrScreen.mMode;
|
|
| 97 | 92 |
} |
| 98 | 93 |
|
| 99 | 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 100 | 95 |
|
| 101 | 96 |
public static void savePreferences(SharedPreferences.Editor editor) |
| 102 | 97 |
{
|
| 103 |
editor.putString("curr_state_name", mCurrState.name() );
|
|
| 98 |
editor.putString("curr_state_name", mCurrScreen.name() );
|
|
| 104 | 99 |
} |
| 105 | 100 |
|
| 106 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 107 | 102 |
|
| 108 | 103 |
public static void restorePreferences(SharedPreferences preferences) |
| 109 | 104 |
{
|
| 110 |
String currStateName = preferences.getString("curr_state_name", ScreenList.PLAY.name() );
|
|
| 111 |
mCurrState = getStateFromName(currStateName);
|
|
| 105 |
String currScreenName = preferences.getString("curr_state_name", ScreenList.PLAY.name() );
|
|
| 106 |
mCurrScreen = getScreenFromName(currScreenName);
|
|
| 112 | 107 |
} |
| 113 | 108 |
|
| 114 | 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 115 | 110 |
|
| 116 | 111 |
public static void goBack(RubikActivity act) |
| 117 | 112 |
{
|
| 118 |
switchState(act, mCurrState.mBack );
|
|
| 113 |
switchScreen(act, mCurrScreen.mBack );
|
|
| 119 | 114 |
} |
| 120 | 115 |
|
| 121 | 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 122 | 117 |
|
| 123 |
public static void setState(RubikActivity act)
|
|
| 118 |
public static void setScreen(RubikActivity act)
|
|
| 124 | 119 |
{
|
| 125 |
mCurrState.enterState(act);
|
|
| 120 |
mCurrScreen.enterScreen(act);
|
|
| 126 | 121 |
} |
| 127 | 122 |
|
| 128 | 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 129 | 124 |
|
| 130 |
public static void switchState(RubikActivity act, ScreenList next)
|
|
| 125 |
public static void switchScreen(RubikActivity act, ScreenList next)
|
|
| 131 | 126 |
{
|
| 132 | 127 |
if( next!=null ) |
| 133 | 128 |
{
|
| ... | ... | |
| 140 | 135 |
analytics.logEvent(FirebaseAnalytics.Event.LEVEL_START, bundle); |
| 141 | 136 |
} |
| 142 | 137 |
|
| 143 |
if( mCurrState!=null ) mCurrState.leaveState(act);
|
|
| 144 |
next.enterState(act);
|
|
| 145 |
mCurrState = next;
|
|
| 138 |
if( mCurrScreen !=null ) mCurrScreen.leaveScreen(act);
|
|
| 139 |
next.enterScreen(act);
|
|
| 140 |
mCurrScreen = next;
|
|
| 146 | 141 |
} |
| 147 | 142 |
else |
| 148 | 143 |
{
|
| ... | ... | |
| 161 | 156 |
|
| 162 | 157 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 163 | 158 |
|
| 164 |
public RubikScreenAbstract getStateClass()
|
|
| 159 |
public RubikScreenAbstract getScreenClass()
|
|
| 165 | 160 |
{
|
| 166 | 161 |
return mClass; |
| 167 | 162 |
} |
| 168 | 163 |
|
| 169 | 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 170 | 165 |
|
| 171 |
public void leaveState(RubikActivity act)
|
|
| 166 |
public void leaveScreen(RubikActivity act)
|
|
| 172 | 167 |
{
|
| 173 |
mClass.leaveState(act);
|
|
| 168 |
mClass.leaveScreen(act);
|
|
| 174 | 169 |
} |
| 175 | 170 |
|
| 176 | 171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 177 | 172 |
|
| 178 |
public void enterState(RubikActivity act)
|
|
| 173 |
public void enterScreen(RubikActivity act)
|
|
| 179 | 174 |
{
|
| 180 |
mClass.enterState(act);
|
|
| 175 |
mClass.enterScreen(act);
|
|
| 181 | 176 |
} |
| 182 | 177 |
} |
| src/main/java/org/distorted/solvers/SolverMain.java | ||
|---|---|---|
| 119 | 119 |
|
| 120 | 120 |
public void run() |
| 121 | 121 |
{
|
| 122 |
RubikScreenSolver solver = (RubikScreenSolver) ScreenList.SVER.getStateClass();
|
|
| 122 |
RubikScreenSolver solver = (RubikScreenSolver) ScreenList.SVER.getScreenClass();
|
|
| 123 | 123 |
|
| 124 | 124 |
if( mObject == ObjectList.CUBE && mSize == 3) |
| 125 | 125 |
{
|
| src/main/java/org/distorted/tutorials/TutorialActivity.java | ||
|---|---|---|
| 339 | 339 |
|
| 340 | 340 |
public boolean isLocked() |
| 341 | 341 |
{
|
| 342 |
ScreenList state = ScreenList.getCurrentState();
|
|
| 342 |
ScreenList state = ScreenList.getCurrentScreen();
|
|
| 343 | 343 |
|
| 344 | 344 |
if( state== ScreenList.PLAY || state== ScreenList.READ || state== ScreenList.SOLV ) |
| 345 | 345 |
{
|
| src/main/java/org/distorted/tutorials/TutorialState.java | ||
|---|---|---|
| 176 | 176 |
@Override |
| 177 | 177 |
public void onClick(View v) |
| 178 | 178 |
{
|
| 179 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getStateClass();
|
|
| 179 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
| 180 | 180 |
int size = play.getSize(); |
| 181 | 181 |
int object= play.getObject(); |
| 182 | 182 |
int sizeIndex = ObjectList.getSizeIndex(object,size); |
Also available in: Unified diff
Cube Control: step 2.