Revision be576d14
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/dialogs/RubikDialogNewRecord.java | ||
---|---|---|
40 | 40 |
import org.distorted.main.RubikActivity; |
41 | 41 |
import org.distorted.objects.ObjectList; |
42 | 42 |
import org.distorted.scores.RubikScores; |
43 |
import org.distorted.states.RubikState;
|
|
43 |
import org.distorted.states.StateList;
|
|
44 | 44 |
import org.distorted.states.RubikStatePlay; |
45 | 45 |
|
46 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
98 | 98 |
RubikScores scores = RubikScores.getInstance(); |
99 | 99 |
String name = scores.getName(); |
100 | 100 |
Bundle bundle = new Bundle(); |
101 |
RubikState.switchState(act,RubikState.PLAY);
|
|
101 |
StateList.switchState(act, StateList.PLAY);
|
|
102 | 102 |
|
103 | 103 |
if( name.length()>0 ) |
104 | 104 |
{ |
105 |
RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass();
|
|
105 |
RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
|
|
106 | 106 |
int object = play.getObject(); |
107 | 107 |
int size = play.getSize(); |
108 | 108 |
int sizeIndex = ObjectList.getSizeIndex(object,size); |
... | ... | |
131 | 131 |
public void onClick(DialogInterface dialog, int which) |
132 | 132 |
{ |
133 | 133 |
RubikActivity act = (RubikActivity)getActivity(); |
134 |
RubikState.switchState(act,RubikState.PLAY);
|
|
134 |
StateList.switchState(act, StateList.PLAY);
|
|
135 | 135 |
} |
136 | 136 |
}); |
137 | 137 |
|
src/main/java/org/distorted/dialogs/RubikDialogPatternView.java | ||
---|---|---|
31 | 31 |
import org.distorted.objects.ObjectList; |
32 | 32 |
import org.distorted.patterns.RubikPattern; |
33 | 33 |
import org.distorted.patterns.RubikPatternList; |
34 |
import org.distorted.states.RubikState;
|
|
34 |
import org.distorted.states.StateList;
|
|
35 | 35 |
import org.distorted.states.RubikStatePattern; |
36 | 36 |
|
37 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
99 | 99 |
|
100 | 100 |
ract.setupObject(list, size, moves); |
101 | 101 |
|
102 |
RubikStatePattern state = (RubikStatePattern) RubikState.PATT.getStateClass();
|
|
102 |
RubikStatePattern state = (RubikStatePattern) StateList.PATT.getStateClass();
|
|
103 | 103 |
|
104 | 104 |
state.setPattern(ract, mTab, groupPosition, childPosition); |
105 | 105 |
|
src/main/java/org/distorted/dialogs/RubikDialogSetName.java | ||
---|---|---|
42 | 42 |
import org.distorted.main.RubikActivity; |
43 | 43 |
import org.distorted.objects.ObjectList; |
44 | 44 |
import org.distorted.scores.RubikScores; |
45 |
import org.distorted.states.RubikState;
|
|
45 |
import org.distorted.states.StateList;
|
|
46 | 46 |
import org.distorted.states.RubikStatePlay; |
47 | 47 |
|
48 | 48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
142 | 142 |
} |
143 | 143 |
|
144 | 144 |
RubikActivity act = (RubikActivity)getActivity(); |
145 |
RubikState.switchState(act,RubikState.PLAY);
|
|
145 |
StateList.switchState(act, StateList.PLAY);
|
|
146 | 146 |
RubikScores.getInstance().setName(name); |
147 |
RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass();
|
|
147 |
RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
|
|
148 | 148 |
|
149 | 149 |
int object = play.getObject(); |
150 | 150 |
int size = play.getSize(); |
src/main/java/org/distorted/dialogs/RubikDialogSolved.java | ||
---|---|---|
38 | 38 |
|
39 | 39 |
import org.distorted.main.R; |
40 | 40 |
import org.distorted.main.RubikActivity; |
41 |
import org.distorted.states.RubikState;
|
|
41 |
import org.distorted.states.StateList;
|
|
42 | 42 |
|
43 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
44 | 44 |
|
... | ... | |
70 | 70 |
public void onClick(DialogInterface dialog, int which) |
71 | 71 |
{ |
72 | 72 |
RubikActivity act = (RubikActivity)getActivity(); |
73 |
RubikState.switchState(act,RubikState.PLAY);
|
|
73 |
StateList.switchState(act, StateList.PLAY);
|
|
74 | 74 |
} |
75 | 75 |
}); |
76 | 76 |
|
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
41 | 41 |
import org.distorted.scores.RubikScores; |
42 | 42 |
import org.distorted.scores.RubikScoresDownloader; |
43 | 43 |
import org.distorted.objects.ObjectList; |
44 |
import org.distorted.states.RubikState;
|
|
44 |
import org.distorted.states.StateList;
|
|
45 | 45 |
import org.distorted.states.RubikStatePlay; |
46 | 46 |
|
47 | 47 |
import java.util.Locale; |
... | ... | |
204 | 204 |
view.onResume(); |
205 | 205 |
view.initialize(); |
206 | 206 |
restorePreferences(); |
207 |
RubikState.setState(this);
|
|
207 |
StateList.setState(this);
|
|
208 | 208 |
|
209 | 209 |
if( mJustStarted ) |
210 | 210 |
{ |
... | ... | |
215 | 215 |
} |
216 | 216 |
|
217 | 217 |
boolean success = false; |
218 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
|
|
218 |
RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
|
|
219 | 219 |
int object = play.getObject(); |
220 | 220 |
int size = play.getSize(); |
221 | 221 |
|
... | ... | |
267 | 267 |
BaseEffect.Type.getType(i).savePreferences(editor); |
268 | 268 |
} |
269 | 269 |
|
270 |
for (int i=0; i<RubikState.LENGTH; i++)
|
|
270 |
for (int i = 0; i< StateList.LENGTH; i++)
|
|
271 | 271 |
{ |
272 |
RubikState.getState(i).getStateClass().savePreferences(editor);
|
|
272 |
StateList.getState(i).getStateClass().savePreferences(editor);
|
|
273 | 273 |
} |
274 | 274 |
|
275 |
RubikState.savePreferences(editor);
|
|
275 |
StateList.savePreferences(editor);
|
|
276 | 276 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
277 | 277 |
view.getPreRender().savePreferences(editor); |
278 | 278 |
|
... | ... | |
292 | 292 |
BaseEffect.Type.getType(i).restorePreferences(preferences); |
293 | 293 |
} |
294 | 294 |
|
295 |
for (int i=0; i< RubikState.LENGTH; i++)
|
|
295 |
for (int i = 0; i< StateList.LENGTH; i++)
|
|
296 | 296 |
{ |
297 |
RubikState.getState(i).getStateClass().restorePreferences(preferences);
|
|
297 |
StateList.getState(i).getStateClass().restorePreferences(preferences);
|
|
298 | 298 |
} |
299 | 299 |
|
300 |
RubikState.restorePreferences(preferences);
|
|
300 |
StateList.restorePreferences(preferences);
|
|
301 | 301 |
|
302 | 302 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
303 | 303 |
view.getPreRender().restorePreferences(preferences); |
... | ... | |
503 | 503 |
|
504 | 504 |
public boolean isLocked() |
505 | 505 |
{ |
506 |
RubikState state = RubikState.getCurrentState();
|
|
506 |
StateList state = StateList.getCurrentState();
|
|
507 | 507 |
|
508 |
if( state==RubikState.PLAY || state==RubikState.READ || state==RubikState.SOLV )
|
|
508 |
if( state== StateList.PLAY || state== StateList.READ || state== StateList.SOLV )
|
|
509 | 509 |
{ |
510 | 510 |
return mIsLocked; |
511 | 511 |
} |
src/main/java/org/distorted/main/RubikPreRender.java | ||
---|---|---|
31 | 31 |
import org.distorted.objects.TwistyObject; |
32 | 32 |
import org.distorted.objects.ObjectList; |
33 | 33 |
import org.distorted.scores.RubikScores; |
34 |
import org.distorted.states.RubikState;
|
|
34 |
import org.distorted.states.StateList;
|
|
35 | 35 |
import org.distorted.states.RubikStateSolving; |
36 | 36 |
|
37 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
156 | 156 |
|
157 | 157 |
if( solved && !mIsSolved ) |
158 | 158 |
{ |
159 |
if( RubikState.getCurrentState()==RubikState.SOLV )
|
|
159 |
if( StateList.getCurrentState()== StateList.SOLV )
|
|
160 | 160 |
{ |
161 |
RubikStateSolving solving = (RubikStateSolving)RubikState.SOLV.getStateClass();
|
|
161 |
RubikStateSolving solving = (RubikStateSolving) StateList.SOLV.getStateClass();
|
|
162 | 162 |
mNewRecord = solving.getRecord(); |
163 | 163 |
|
164 | 164 |
if( mNewRecord< 0 ) |
... | ... | |
544 | 544 |
@Override |
545 | 545 |
public void run() |
546 | 546 |
{ |
547 |
RubikState.switchState( act, RubikState.READ);
|
|
547 |
StateList.switchState( act, StateList.READ);
|
|
548 | 548 |
} |
549 | 549 |
}); |
550 | 550 |
} |
551 | 551 |
|
552 | 552 |
if( i==BaseEffect.Type.WIN.ordinal() ) |
553 | 553 |
{ |
554 |
if( RubikState.getCurrentState()==RubikState.SOLV )
|
|
554 |
if( StateList.getCurrentState()== StateList.SOLV )
|
|
555 | 555 |
{ |
556 | 556 |
final RubikActivity act = (RubikActivity)mView.getContext(); |
557 | 557 |
Bundle bundle = new Bundle(); |
... | ... | |
575 | 575 |
@Override |
576 | 576 |
public void run() |
577 | 577 |
{ |
578 |
RubikState.switchState( act, RubikState.DONE);
|
|
578 |
StateList.switchState( act, StateList.DONE);
|
|
579 | 579 |
} |
580 | 580 |
}); |
581 | 581 |
} |
src/main/java/org/distorted/main/RubikSurfaceView.java | ||
---|---|---|
35 | 35 |
import org.distorted.objects.TwistyObject; |
36 | 36 |
import org.distorted.objects.Movement; |
37 | 37 |
import org.distorted.solvers.SolverMain; |
38 |
import org.distorted.states.RubikState;
|
|
38 |
import org.distorted.states.StateList;
|
|
39 | 39 |
import org.distorted.states.RubikStatePlay; |
40 | 40 |
import org.distorted.states.RubikStateSolver; |
41 | 41 |
import org.distorted.states.RubikStateSolving; |
... | ... | |
295 | 295 |
|
296 | 296 |
private void setUpDragOrRotate(boolean down, float x, float y) |
297 | 297 |
{ |
298 |
int mode = RubikState.getMode();
|
|
298 |
int mode = StateList.getMode();
|
|
299 | 299 |
|
300 | 300 |
if( mode==MODE_DRAG ) |
301 | 301 |
{ |
... | ... | |
324 | 324 |
|
325 | 325 |
if( down ) |
326 | 326 |
{ |
327 |
RubikStateSolver solver = (RubikStateSolver) RubikState.SVER.getStateClass();
|
|
327 |
RubikStateSolver solver = (RubikStateSolver) StateList.SVER.getStateClass();
|
|
328 | 328 |
mLastCubitFace = mMovement.getTouchedFace(); |
329 | 329 |
float[] point = mMovement.getTouchedPoint3D(); |
330 | 330 |
int color = solver.getCurrentColor(); |
... | ... | |
413 | 413 |
|
414 | 414 |
if( angle!=0 ) |
415 | 415 |
{ |
416 |
if( RubikState.getCurrentState()==RubikState.SOLV )
|
|
416 |
if( StateList.getCurrentState()== StateList.SOLV )
|
|
417 | 417 |
{ |
418 |
RubikStateSolving solving = (RubikStateSolving)RubikState.SOLV.getStateClass();
|
|
418 |
RubikStateSolving solving = (RubikStateSolving) StateList.SOLV.getStateClass();
|
|
419 | 419 |
solving.addMove(mCurrentAxis, mCurrentRow, angle); |
420 | 420 |
} |
421 |
if( RubikState.getCurrentState()==RubikState.PLAY )
|
|
421 |
if( StateList.getCurrentState()== StateList.PLAY )
|
|
422 | 422 |
{ |
423 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
|
|
423 |
RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
|
|
424 | 424 |
play.addMove(mCurrentAxis, mCurrentRow, angle); |
425 | 425 |
} |
426 | 426 |
} |
... | ... | |
474 | 474 |
|
475 | 475 |
object.beginNewRotation( mCurrentAxis, mCurrentRow ); |
476 | 476 |
|
477 |
if( RubikState.getCurrentState()==RubikState.READ )
|
|
477 |
if( StateList.getCurrentState()== StateList.READ )
|
|
478 | 478 |
{ |
479 |
RubikStateSolving solving = (RubikStateSolving)RubikState.SOLV.getStateClass();
|
|
479 |
RubikStateSolving solving = (RubikStateSolving) StateList.SOLV.getStateClass();
|
|
480 | 480 |
solving.resetElapsed(); |
481 | 481 |
|
482 | 482 |
final RubikActivity act = (RubikActivity)getContext(); |
... | ... | |
486 | 486 |
@Override |
487 | 487 |
public void run() |
488 | 488 |
{ |
489 |
RubikState.switchState( act, RubikState.SOLV);
|
|
489 |
StateList.switchState( act, StateList.SOLV);
|
|
490 | 490 |
} |
491 | 491 |
}); |
492 | 492 |
} |
src/main/java/org/distorted/solvers/SolverMain.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
import org.distorted.main.R; |
25 | 25 |
import org.distorted.objects.ObjectList; |
26 |
import org.distorted.states.RubikState;
|
|
26 |
import org.distorted.states.StateList;
|
|
27 | 27 |
import org.distorted.states.RubikStateSolver; |
28 | 28 |
|
29 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
119 | 119 |
|
120 | 120 |
public void run() |
121 | 121 |
{ |
122 |
RubikStateSolver solver = (RubikStateSolver) RubikState.SVER.getStateClass();
|
|
122 |
RubikStateSolver solver = (RubikStateSolver) StateList.SVER.getStateClass();
|
|
123 | 123 |
|
124 | 124 |
if( mObject == ObjectList.CUBE && mSize == 3) |
125 | 125 |
{ |
src/main/java/org/distorted/states/RubikState.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 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.states; |
|
21 |
|
|
22 |
import android.content.SharedPreferences; |
|
23 |
import android.os.Bundle; |
|
24 |
|
|
25 |
import com.google.firebase.analytics.FirebaseAnalytics; |
|
26 |
|
|
27 |
import org.distorted.main.RubikActivity; |
|
28 |
import static org.distorted.main.RubikSurfaceView.*; |
|
29 |
|
|
30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
31 |
|
|
32 |
public enum RubikState |
|
33 |
{ |
|
34 |
PLAY ( null , MODE_ROTATE , new RubikStatePlay() ), |
|
35 |
SOLV ( PLAY , MODE_ROTATE , new RubikStateSolving() ), |
|
36 |
PATT ( PLAY , MODE_DRAG , new RubikStatePattern() ), |
|
37 |
SVER ( PLAY , MODE_REPLACE, new RubikStateSolver() ), |
|
38 |
SOLU ( SVER , MODE_DRAG , new RubikStateSolution() ), |
|
39 |
READ ( PLAY , MODE_ROTATE , new RubikStateReady() ), |
|
40 |
DONE ( PLAY , MODE_DRAG , new RubikStateDone() ), |
|
41 |
; |
|
42 |
|
|
43 |
public static final int LENGTH = values().length; |
|
44 |
private final RubikState mBack; |
|
45 |
private int mMode; |
|
46 |
private final RubikStateAbstract mClass; |
|
47 |
private static final RubikState[] states; |
|
48 |
|
|
49 |
private static RubikState mCurrState; |
|
50 |
|
|
51 |
static |
|
52 |
{ |
|
53 |
int i = 0; |
|
54 |
states = new RubikState[LENGTH]; |
|
55 |
|
|
56 |
for(RubikState state: RubikState.values()) |
|
57 |
{ |
|
58 |
states[i] = state; |
|
59 |
i++; |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
public static RubikState getState(int ordinal) |
|
66 |
{ |
|
67 |
return ordinal>=0 && ordinal<LENGTH ? states[ordinal] : PLAY; |
|
68 |
} |
|
69 |
|
|
70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
71 |
|
|
72 |
public static RubikState getStateFromName(String name) |
|
73 |
{ |
|
74 |
for(int i=0; i<LENGTH; i++) |
|
75 |
{ |
|
76 |
if( name.equals(states[i].name()) ) |
|
77 |
{ |
|
78 |
return states[i]; |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
return PLAY; |
|
83 |
} |
|
84 |
|
|
85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
86 |
|
|
87 |
public static RubikState getCurrentState() |
|
88 |
{ |
|
89 |
return mCurrState; |
|
90 |
} |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
public static int getMode() |
|
95 |
{ |
|
96 |
return mCurrState.mMode; |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
public static void savePreferences(SharedPreferences.Editor editor) |
|
102 |
{ |
|
103 |
editor.putString("curr_state_name", mCurrState.name() ); |
|
104 |
} |
|
105 |
|
|
106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
107 |
|
|
108 |
public static void restorePreferences(SharedPreferences preferences) |
|
109 |
{ |
|
110 |
String currStateName = preferences.getString("curr_state_name", RubikState.PLAY.name() ); |
|
111 |
mCurrState = getStateFromName(currStateName); |
|
112 |
} |
|
113 |
|
|
114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
115 |
|
|
116 |
public static void goBack(RubikActivity act) |
|
117 |
{ |
|
118 |
switchState(act, mCurrState.mBack ); |
|
119 |
} |
|
120 |
|
|
121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
122 |
|
|
123 |
public static void setState(RubikActivity act) |
|
124 |
{ |
|
125 |
mCurrState.enterState(act); |
|
126 |
} |
|
127 |
|
|
128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
129 |
|
|
130 |
public static void switchState(RubikActivity act, RubikState next) |
|
131 |
{ |
|
132 |
if( next!=null ) |
|
133 |
{ |
|
134 |
FirebaseAnalytics analytics = act.getAnalytics(); |
|
135 |
|
|
136 |
if( analytics!=null ) |
|
137 |
{ |
|
138 |
Bundle bundle = new Bundle(); |
|
139 |
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, next.toString()); |
|
140 |
analytics.logEvent(FirebaseAnalytics.Event.LEVEL_START, bundle); |
|
141 |
} |
|
142 |
|
|
143 |
if( mCurrState!=null ) mCurrState.leaveState(act); |
|
144 |
next.enterState(act); |
|
145 |
mCurrState = next; |
|
146 |
} |
|
147 |
else |
|
148 |
{ |
|
149 |
act.finish(); |
|
150 |
} |
|
151 |
} |
|
152 |
|
|
153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
154 |
|
|
155 |
RubikState(RubikState back, int mode, RubikStateAbstract clazz) |
|
156 |
{ |
|
157 |
mBack = back; |
|
158 |
mMode = mode; |
|
159 |
mClass= clazz; |
|
160 |
} |
|
161 |
|
|
162 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
163 |
|
|
164 |
public RubikStateAbstract getStateClass() |
|
165 |
{ |
|
166 |
return mClass; |
|
167 |
} |
|
168 |
|
|
169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
170 |
|
|
171 |
public void leaveState(RubikActivity act) |
|
172 |
{ |
|
173 |
mClass.leaveState(act); |
|
174 |
} |
|
175 |
|
|
176 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
177 |
|
|
178 |
public void enterState(RubikActivity act) |
|
179 |
{ |
|
180 |
mClass.enterState(act); |
|
181 |
} |
|
182 |
} |
src/main/java/org/distorted/states/RubikStateDone.java | ||
---|---|---|
90 | 90 |
@Override |
91 | 91 |
public void onClick(View v) |
92 | 92 |
{ |
93 |
RubikState.goBack(act);
|
|
93 |
StateList.goBack(act);
|
|
94 | 94 |
} |
95 | 95 |
}); |
96 | 96 |
|
src/main/java/org/distorted/states/RubikStatePattern.java | ||
---|---|---|
60 | 60 |
|
61 | 61 |
void leaveState(RubikActivity act) |
62 | 62 |
{ |
63 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
|
|
63 |
RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
|
|
64 | 64 |
|
65 | 65 |
ObjectList object = RubikPatternList.getObject(mPatternOrdinal); |
66 | 66 |
int size = RubikPatternList.getSize(mPatternOrdinal); |
... | ... | |
82 | 82 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
83 | 83 |
mTitleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
84 | 84 |
|
85 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
|
|
85 |
RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
|
|
86 | 86 |
int obj = play.getObject(); |
87 | 87 |
int size = play.getSize(); |
88 | 88 |
|
... | ... | |
201 | 201 |
{ |
202 | 202 |
diag.rememberState(); |
203 | 203 |
diag.dismiss(); |
204 |
RubikState.goBack(act);
|
|
204 |
StateList.goBack(act);
|
|
205 | 205 |
} |
206 | 206 |
} |
207 | 207 |
}); |
src/main/java/org/distorted/states/RubikStatePlay.java | ||
---|---|---|
420 | 420 |
@Override |
421 | 421 |
public void onClick(View v) |
422 | 422 |
{ |
423 |
if( act.getPreRender().canPlay() && RubikState.getCurrentState()==RubikState.PLAY )
|
|
423 |
if( act.getPreRender().canPlay() && StateList.getCurrentState()== StateList.PLAY )
|
|
424 | 424 |
{ |
425 | 425 |
mObject = obj; |
426 | 426 |
mSize = sizes[index]; |
... | ... | |
546 | 546 |
{ |
547 | 547 |
switch(button) |
548 | 548 |
{ |
549 |
case 0: RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass();
|
|
549 |
case 0: RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
|
|
550 | 550 |
int object = play.getObject(); |
551 | 551 |
int size = play.getSize(); |
552 | 552 |
int sizeIndex = ObjectList.getSizeIndex(object,size); |
... | ... | |
559 | 559 |
scores.setArguments(bundle); |
560 | 560 |
scores.show(act.getSupportFragmentManager(), null); |
561 | 561 |
break; |
562 |
case 1: RubikState.switchState(act,RubikState.PATT);
|
|
562 |
case 1: StateList.switchState(act, StateList.PATT);
|
|
563 | 563 |
break; |
564 |
case 2: RubikState.switchState(act,RubikState.SVER);
|
|
564 |
case 2: StateList.switchState(act, StateList.SVER);
|
|
565 | 565 |
break; |
566 | 566 |
case 3: RubikDialogAbout diag = new RubikDialogAbout(); |
567 | 567 |
diag.show(act.getSupportFragmentManager(), null); |
src/main/java/org/distorted/states/RubikStateReady.java | ||
---|---|---|
109 | 109 |
@Override |
110 | 110 |
public void onClick(View v) |
111 | 111 |
{ |
112 |
RubikState.goBack(act);
|
|
112 |
StateList.goBack(act);
|
|
113 | 113 |
} |
114 | 114 |
}); |
115 | 115 |
} |
src/main/java/org/distorted/states/RubikStateSolution.java | ||
---|---|---|
213 | 213 |
@Override |
214 | 214 |
public void onClick(View v) |
215 | 215 |
{ |
216 |
RubikState.goBack(act);
|
|
216 |
StateList.goBack(act);
|
|
217 | 217 |
} |
218 | 218 |
}); |
219 | 219 |
} |
src/main/java/org/distorted/states/RubikStateSolver.java | ||
---|---|---|
87 | 87 |
mCurrentObjectSize = ImplementedSolversList.getObjectSize(0); |
88 | 88 |
|
89 | 89 |
act.setupObject(mCurrentObject, mCurrentObjectSize, null); |
90 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
|
|
90 |
RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
|
|
91 | 91 |
play.setObjectAndSize(act, mCurrentObject, mCurrentObjectSize); |
92 | 92 |
|
93 | 93 |
mFaceColors = ObjectList.retFaceColors(mCurrentObject); |
... | ... | |
257 | 257 |
{ |
258 | 258 |
RubikPreRender pre = act.getPreRender(); |
259 | 259 |
pre.resetAllTextureMaps(); |
260 |
RubikState.goBack(act);
|
|
260 |
StateList.goBack(act);
|
|
261 | 261 |
} |
262 | 262 |
}); |
263 | 263 |
} |
... | ... | |
316 | 316 |
@Override |
317 | 317 |
public void run() |
318 | 318 |
{ |
319 |
RubikState.switchState(act,RubikState.SOLU);
|
|
320 |
RubikStateSolution solution = (RubikStateSolution) RubikState.SOLU.getStateClass();
|
|
319 |
StateList.switchState(act, StateList.SOLU);
|
|
320 |
RubikStateSolution solution = (RubikStateSolution) StateList.SOLU.getStateClass();
|
|
321 | 321 |
solution.setupMoves(act, moves); |
322 | 322 |
} |
323 | 323 |
}); |
src/main/java/org/distorted/states/RubikStateSolving.java | ||
---|---|---|
155 | 155 |
@Override |
156 | 156 |
public void onClick(View v) |
157 | 157 |
{ |
158 |
RubikState.goBack(act);
|
|
158 |
StateList.goBack(act);
|
|
159 | 159 |
} |
160 | 160 |
}); |
161 | 161 |
} |
... | ... | |
347 | 347 |
|
348 | 348 |
mElapsed = System.currentTimeMillis()-mStartTime; |
349 | 349 |
|
350 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
|
|
350 |
RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
|
|
351 | 351 |
int object = play.getObject(); |
352 | 352 |
int size = play.getSize(); |
353 | 353 |
int level = play.getLevel(); |
src/main/java/org/distorted/states/StateList.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 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.states; |
|
21 |
|
|
22 |
import android.content.SharedPreferences; |
|
23 |
import android.os.Bundle; |
|
24 |
|
|
25 |
import com.google.firebase.analytics.FirebaseAnalytics; |
|
26 |
|
|
27 |
import org.distorted.main.RubikActivity; |
|
28 |
import static org.distorted.main.RubikSurfaceView.*; |
|
29 |
|
|
30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
31 |
|
|
32 |
public enum StateList |
|
33 |
{ |
|
34 |
PLAY ( null , MODE_ROTATE , new RubikStatePlay() ), |
|
35 |
SOLV ( PLAY , MODE_ROTATE , new RubikStateSolving() ), |
|
36 |
PATT ( PLAY , MODE_DRAG , new RubikStatePattern() ), |
|
37 |
SVER ( PLAY , MODE_REPLACE, new RubikStateSolver() ), |
|
38 |
SOLU ( SVER , MODE_DRAG , new RubikStateSolution() ), |
|
39 |
READ ( PLAY , MODE_ROTATE , new RubikStateReady() ), |
|
40 |
DONE ( PLAY , MODE_DRAG , new RubikStateDone() ), |
|
41 |
; |
|
42 |
|
|
43 |
public static final int LENGTH = values().length; |
|
44 |
private final StateList mBack; |
|
45 |
private int mMode; |
|
46 |
private final RubikStateAbstract mClass; |
|
47 |
private static final StateList[] states; |
|
48 |
|
|
49 |
private static StateList mCurrState; |
|
50 |
|
|
51 |
static |
|
52 |
{ |
|
53 |
int i = 0; |
|
54 |
states = new StateList[LENGTH]; |
|
55 |
|
|
56 |
for(StateList state: StateList.values()) |
|
57 |
{ |
|
58 |
states[i] = state; |
|
59 |
i++; |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
public static StateList getState(int ordinal) |
|
66 |
{ |
|
67 |
return ordinal>=0 && ordinal<LENGTH ? states[ordinal] : PLAY; |
|
68 |
} |
|
69 |
|
|
70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
71 |
|
|
72 |
public static StateList getStateFromName(String name) |
|
73 |
{ |
|
74 |
for(int i=0; i<LENGTH; i++) |
|
75 |
{ |
|
76 |
if( name.equals(states[i].name()) ) |
|
77 |
{ |
|
78 |
return states[i]; |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
return PLAY; |
|
83 |
} |
|
84 |
|
|
85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
86 |
|
|
87 |
public static StateList getCurrentState() |
|
88 |
{ |
|
89 |
return mCurrState; |
|
90 |
} |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
public static int getMode() |
|
95 |
{ |
|
96 |
return mCurrState.mMode; |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
public static void savePreferences(SharedPreferences.Editor editor) |
|
102 |
{ |
|
103 |
editor.putString("curr_state_name", mCurrState.name() ); |
|
104 |
} |
|
105 |
|
|
106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
107 |
|
|
108 |
public static void restorePreferences(SharedPreferences preferences) |
|
109 |
{ |
|
110 |
String currStateName = preferences.getString("curr_state_name", StateList.PLAY.name() ); |
|
111 |
mCurrState = getStateFromName(currStateName); |
|
112 |
} |
|
113 |
|
|
114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
115 |
|
|
116 |
public static void goBack(RubikActivity act) |
|
117 |
{ |
|
118 |
switchState(act, mCurrState.mBack ); |
|
119 |
} |
|
120 |
|
|
121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
122 |
|
|
123 |
public static void setState(RubikActivity act) |
|
124 |
{ |
|
125 |
mCurrState.enterState(act); |
|
126 |
} |
|
127 |
|
|
128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
129 |
|
|
130 |
public static void switchState(RubikActivity act, StateList next) |
|
131 |
{ |
|
132 |
if( next!=null ) |
|
133 |
{ |
|
134 |
FirebaseAnalytics analytics = act.getAnalytics(); |
|
135 |
|
|
136 |
if( analytics!=null ) |
|
137 |
{ |
|
138 |
Bundle bundle = new Bundle(); |
|
139 |
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, next.toString()); |
|
140 |
analytics.logEvent(FirebaseAnalytics.Event.LEVEL_START, bundle); |
|
141 |
} |
|
142 |
|
|
143 |
if( mCurrState!=null ) mCurrState.leaveState(act); |
|
144 |
next.enterState(act); |
|
145 |
mCurrState = next; |
|
146 |
} |
|
147 |
else |
|
148 |
{ |
|
149 |
act.finish(); |
|
150 |
} |
|
151 |
} |
|
152 |
|
|
153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
154 |
|
|
155 |
StateList(StateList back, int mode, RubikStateAbstract clazz) |
|
156 |
{ |
|
157 |
mBack = back; |
|
158 |
mMode = mode; |
|
159 |
mClass= clazz; |
|
160 |
} |
|
161 |
|
|
162 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
163 |
|
|
164 |
public RubikStateAbstract getStateClass() |
|
165 |
{ |
|
166 |
return mClass; |
|
167 |
} |
|
168 |
|
|
169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
170 |
|
|
171 |
public void leaveState(RubikActivity act) |
|
172 |
{ |
|
173 |
mClass.leaveState(act); |
|
174 |
} |
|
175 |
|
|
176 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
177 |
|
|
178 |
public void enterState(RubikActivity act) |
|
179 |
{ |
|
180 |
mClass.enterState(act); |
|
181 |
} |
|
182 |
} |
Also available in: Unified diff
Rename some classes.