Revision 42772cff
Added by Leszek Koltunski almost 5 years ago
src/main/java/org/distorted/effect/ScrambleEffect.java | ||
---|---|---|
83 | 83 |
mLastVector = -1; |
84 | 84 |
} |
85 | 85 |
|
86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
87 |
|
|
88 |
public static Type getType(int ordinal) |
|
89 |
{ |
|
90 |
return types[ordinal]; |
|
91 |
} |
|
92 |
|
|
93 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
94 | 87 |
|
95 | 88 |
public static String[] getNames() |
... | ... | |
106 | 99 |
|
107 | 100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
108 | 101 |
|
109 |
public static ScrambleEffect create(Type type) throws InstantiationException, IllegalAccessException
|
|
102 |
public static ScrambleEffect create(int ordinal) throws InstantiationException, IllegalAccessException
|
|
110 | 103 |
{ |
111 |
return type.effect.newInstance(); |
|
104 |
return types[ordinal].effect.newInstance();
|
|
112 | 105 |
} |
113 | 106 |
|
114 | 107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/effect/SizeChangeEffect.java | ||
---|---|---|
94 | 94 |
mCube = new RubikCube[NUM_PHASES]; |
95 | 95 |
} |
96 | 96 |
|
97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 |
|
|
99 |
public static Type getType(int index) |
|
100 |
{ |
|
101 |
return types[index]; |
|
102 |
} |
|
103 |
|
|
104 | 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
105 | 98 |
|
106 | 99 |
public static String[] getNames() |
... | ... | |
117 | 110 |
|
118 | 111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
119 | 112 |
|
120 |
public static SizeChangeEffect create(Type type) throws InstantiationException, IllegalAccessException
|
|
113 |
public static SizeChangeEffect create(int ordinal) throws InstantiationException, IllegalAccessException
|
|
121 | 114 |
{ |
122 |
return type.effect.newInstance(); |
|
115 |
return types[ordinal].effect.newInstance();
|
|
123 | 116 |
} |
124 | 117 |
|
125 | 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/effect/SolveEffect.java | ||
---|---|---|
88 | 88 |
mNodeEffects = new Effect[NUM_PHASES][]; |
89 | 89 |
} |
90 | 90 |
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 |
|
|
93 |
public static Type getType(int ordinal) |
|
94 |
{ |
|
95 |
return types[ordinal]; |
|
96 |
} |
|
97 |
|
|
98 | 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
99 | 92 |
|
100 | 93 |
public static String[] getNames() |
... | ... | |
111 | 104 |
|
112 | 105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
113 | 106 |
|
114 |
public static SolveEffect create(Type type) throws InstantiationException, IllegalAccessException
|
|
107 |
public static SolveEffect create(int ordinal) throws InstantiationException, IllegalAccessException
|
|
115 | 108 |
{ |
116 |
return type.effect.newInstance(); |
|
109 |
return types[ordinal].effect.newInstance();
|
|
117 | 110 |
} |
118 | 111 |
|
119 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/magic/RubikActivity.java | ||
---|---|---|
30 | 30 |
import android.view.View; |
31 | 31 |
|
32 | 32 |
import org.distorted.component.HorizontalNumberPicker; |
33 |
import org.distorted.effect.ScrambleEffect; |
|
34 |
import org.distorted.effect.SizeChangeEffect; |
|
35 |
import org.distorted.effect.SolveEffect; |
|
36 | 33 |
import org.distorted.library.main.DistortedLibrary; |
37 | 34 |
|
38 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
43 | 40 |
private static final int SMALLEST_SIZE = 2; |
44 | 41 |
private static final int[] button_ids = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4}; |
45 | 42 |
|
46 |
public static final int DEFAULT_SIZECHANGE_POS = 20; |
|
47 |
public static final int DEFAULT_SOLVE_POS = 20; |
|
48 |
public static final int DEFAULT_SCRAMBLE_POS =100; |
|
49 |
public static final int DEFAULT_SIZECHANGE_TYPE= 1; |
|
50 |
public static final int DEFAULT_SOLVE_TYPE = 1; |
|
51 |
public static final int DEFAULT_SCRAMBLE_TYPE = 0; |
|
52 |
|
|
53 | 43 |
public static final int MIN_SCRAMBLE = 1; |
54 | 44 |
public static final int MAX_SCRAMBLE = 10; |
55 | 45 |
|
56 | 46 |
private static int mSize = DEFAULT_SIZE; |
57 | 47 |
|
58 |
private int mSizeChangePos, mSolvePos, mScramblePos;
|
|
59 |
private int mSizeChangeType, mSolveType, mScrambleType;
|
|
48 |
private int[] mPos;
|
|
49 |
private int[] mType;
|
|
60 | 50 |
|
61 | 51 |
private HorizontalNumberPicker mPicker; |
62 | 52 |
|
... | ... | |
70 | 60 |
setContentView(R.layout.main); |
71 | 61 |
markButton(mSize); |
72 | 62 |
|
63 |
mPos = new int[RubikSettingsEnum.LENGTH]; |
|
64 |
mType= new int[RubikSettingsEnum.LENGTH]; |
|
65 |
|
|
73 | 66 |
mPicker = findViewById(R.id.rubikNumberPicker); |
74 | 67 |
mPicker.setMin(MIN_SCRAMBLE); |
75 | 68 |
mPicker.setMax(MAX_SCRAMBLE); |
76 | 69 |
|
77 | 70 |
restorePreferences(); |
78 |
applyPreferences(); |
|
71 |
|
|
72 |
for (int i=0; i<RubikSettingsEnum.LENGTH; i++) |
|
73 |
{ |
|
74 |
applyPreferences(i); |
|
75 |
} |
|
79 | 76 |
} |
80 | 77 |
|
81 | 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
122 | 119 |
{ |
123 | 120 |
Bundle args = new Bundle(); |
124 | 121 |
|
125 |
args.putInt("SIZECHANGE_Pos" , mSizeChangePos ); |
|
126 |
args.putInt("SOLVE_Pos" , mSolvePos ); |
|
127 |
args.putInt("SCRAMBLE_Pos" , mScramblePos ); |
|
128 |
args.putInt("SIZECHANGE_Type", mSizeChangeType); |
|
129 |
args.putInt("SOLVE_Type" , mSolveType ); |
|
130 |
args.putInt("SCRAMBLE_Type" , mScrambleType ); |
|
122 |
String name; |
|
123 |
|
|
124 |
for (int i=0; i<RubikSettingsEnum.LENGTH; i++) |
|
125 |
{ |
|
126 |
RubikSettingsEnum rse = RubikSettingsEnum.getEnum(i); |
|
127 |
name = rse.name(); |
|
128 |
|
|
129 |
args.putInt(name+"_Pos" , mPos[i]); |
|
130 |
args.putInt(name+"_Type", mType[i]); |
|
131 |
} |
|
131 | 132 |
|
132 | 133 |
RubikSettings settings = new RubikSettings(); |
133 | 134 |
settings.setArguments(args); |
... | ... | |
162 | 163 |
|
163 | 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
164 | 165 |
|
165 |
public void onComplete(int sizeP, int solvP, int scraP, int sizeT, int solvT, int scraT )
|
|
166 |
public void onComplete(int index, int position, int type )
|
|
166 | 167 |
{ |
167 |
mSizeChangePos = sizeP; |
|
168 |
mSolvePos = solvP; |
|
169 |
mScramblePos = scraP; |
|
170 |
mSizeChangeType= sizeT; |
|
171 |
mSolveType = solvT; |
|
172 |
mScrambleType = scraT; |
|
173 |
|
|
174 |
applyPreferences(); |
|
168 |
if( index>=0 && index<RubikSettingsEnum.LENGTH ) |
|
169 |
{ |
|
170 |
mPos[index] = position; |
|
171 |
mType[index]= type; |
|
172 |
|
|
173 |
applyPreferences(index); |
|
174 |
} |
|
175 | 175 |
} |
176 | 176 |
|
177 | 177 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
223 | 223 |
{ |
224 | 224 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
225 | 225 |
SharedPreferences.Editor editor = preferences.edit(); |
226 |
String name; |
|
227 |
|
|
228 |
for (int i=0; i<RubikSettingsEnum.LENGTH; i++) |
|
229 |
{ |
|
230 |
RubikSettingsEnum rse = RubikSettingsEnum.getEnum(i); |
|
231 |
name = rse.name(); |
|
232 |
|
|
233 |
editor.putInt(name+"_Pos" , mPos[i]); |
|
234 |
editor.putInt(name+"_Type", mType[i]); |
|
235 |
} |
|
226 | 236 |
|
227 |
editor.putInt("SIZECHANGE_Pos" , mSizeChangePos ); |
|
228 |
editor.putInt("SOLVE_Pos" , mSolvePos ); |
|
229 |
editor.putInt("SCRAMBLE_Pos" , mScramblePos ); |
|
230 |
editor.putInt("SIZECHANGE_Type", mSizeChangeType); |
|
231 |
editor.putInt("SOLVE_Type" , mSolveType ); |
|
232 |
editor.putInt("SCRAMBLE_Type" , mScrambleType ); |
|
233 |
editor.putInt("scramble" , mPicker.getValue() ); |
|
237 |
editor.putInt("scramble", mPicker.getValue() ); |
|
234 | 238 |
|
235 | 239 |
editor.apply(); |
236 | 240 |
} |
... | ... | |
241 | 245 |
{ |
242 | 246 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
243 | 247 |
|
244 |
mSizeChangePos = preferences.getInt("SIZECHANGE_Pos" , DEFAULT_SIZECHANGE_POS ); |
|
245 |
mSolvePos = preferences.getInt("SOLVE_Pos" , DEFAULT_SOLVE_POS ); |
|
246 |
mScramblePos = preferences.getInt("SCRAMBLE_Pos" , DEFAULT_SCRAMBLE_POS ); |
|
247 |
mSizeChangeType= preferences.getInt("SIZECHANGE_Type", DEFAULT_SIZECHANGE_TYPE); |
|
248 |
mSolveType = preferences.getInt("SOLVE_Type" , DEFAULT_SOLVE_TYPE ); |
|
249 |
mScrambleType = preferences.getInt("SCRAMBLE_Type" , DEFAULT_SCRAMBLE_TYPE ); |
|
250 |
int scramble = preferences.getInt("scramble" , MIN_SCRAMBLE ); |
|
248 |
String name; |
|
249 |
|
|
250 |
for (int i=0; i<RubikSettingsEnum.LENGTH; i++) |
|
251 |
{ |
|
252 |
RubikSettingsEnum rse = RubikSettingsEnum.getEnum(i); |
|
253 |
name = rse.name(); |
|
254 |
|
|
255 |
mPos[i] = preferences.getInt(name+"_Pos" , rse.getDefaultPos() ); |
|
256 |
mType[i] = preferences.getInt(name+"_Type", rse.getDefaultType()); |
|
257 |
} |
|
258 |
|
|
259 |
int scramble= preferences.getInt("scramble", MIN_SCRAMBLE); |
|
251 | 260 |
|
252 | 261 |
mPicker.setValue(scramble); |
253 | 262 |
} |
254 | 263 |
|
255 | 264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
256 | 265 |
|
257 |
private void applyPreferences() |
|
266 |
private void applyPreferences(int index)
|
|
258 | 267 |
{ |
259 | 268 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
260 | 269 |
RubikRenderer renderer = view.getRenderer(); |
261 | 270 |
|
262 |
renderer.setSizeChangeDuration(translateDuration(mSizeChangePos)+1); |
|
263 |
renderer.setSolveDuration(translateDuration(mSolvePos)+1); |
|
264 |
renderer.setScrambleDuration(translateDuration(mScramblePos)+1); |
|
265 |
renderer.setSizeChangeType(SizeChangeEffect.getType(mSizeChangeType)); |
|
266 |
renderer.setSolveType(SolveEffect.getType(mSolveType)); |
|
267 |
renderer.setScrambleType(ScrambleEffect.getType(mScrambleType)); |
|
271 |
renderer.setPos (index, translateDuration(mPos[index])+1); |
|
272 |
renderer.setType(index, mType[index] ); |
|
268 | 273 |
} |
269 | 274 |
|
270 | 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/magic/RubikRenderer.java | ||
---|---|---|
56 | 56 |
private RubikCube mOldCube, mNewCube; |
57 | 57 |
private int mScreenWidth, mScreenHeight; |
58 | 58 |
private MeshFlat mMesh; |
59 |
private SizeChangeEffect.Type mSizeChangeType; |
|
60 |
private SolveEffect.Type mSolveType; |
|
61 |
private ScrambleEffect.Type mScrambleType; |
|
62 |
private int mSizeChangeDuration, mSolveDuration, mScrambleDuration; |
|
59 |
private int[] mPos; |
|
60 |
private int[] mType; |
|
63 | 61 |
|
64 | 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
65 | 63 |
|
... | ... | |
92 | 90 |
mCanScramble = true; |
93 | 91 |
mCanSolve = true; |
94 | 92 |
|
95 |
mSizeChangeType= SizeChangeEffect.Type.TRANSPARENCY; |
|
96 |
mSolveType = SolveEffect.Type.SPIN; |
|
97 |
mScrambleType = ScrambleEffect.Type.NONE; |
|
93 |
mPos = new int[RubikSettingsEnum.LENGTH]; |
|
94 |
mType = new int[RubikSettingsEnum.LENGTH]; |
|
98 | 95 |
|
99 |
mSizeChangeDuration= 1000; |
|
100 |
mSolveDuration = 1000; |
|
101 |
mScrambleDuration = 1000; |
|
96 |
for (int i=0; i<RubikSettingsEnum.LENGTH; i++) |
|
97 |
{ |
|
98 |
mPos[i] = 1000; |
|
99 |
} |
|
102 | 100 |
|
103 | 101 |
mMesh= new MeshFlat(20,20); |
104 | 102 |
mNextCubeSize =RubikActivity.getSize(); |
... | ... | |
247 | 245 |
{ |
248 | 246 |
try |
249 | 247 |
{ |
250 |
SizeChangeEffect effect = SizeChangeEffect.create(mSizeChangeType);
|
|
251 |
mSizeChangeEffectID = effect.start(mSizeChangeDuration,mScreen,mOldCube,mNewCube,this);
|
|
248 |
SizeChangeEffect effect = SizeChangeEffect.create(mType[0]);
|
|
249 |
mSizeChangeEffectID = effect.start(mPos[0],mScreen,mOldCube,mNewCube,this);
|
|
252 | 250 |
} |
253 | 251 |
catch(Exception ex) |
254 | 252 |
{ |
... | ... | |
279 | 277 |
|
280 | 278 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
281 | 279 |
|
282 |
void setSizeChangeDuration(int duration) |
|
283 |
{ |
|
284 |
mSizeChangeDuration = duration; |
|
285 |
} |
|
286 |
|
|
287 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
288 |
|
|
289 |
void setSolveDuration(int duration) |
|
290 |
{ |
|
291 |
mSolveDuration = duration; |
|
292 |
} |
|
293 |
|
|
294 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
295 |
|
|
296 |
void setScrambleDuration(int duration) |
|
297 |
{ |
|
298 |
mScrambleDuration = duration; |
|
299 |
} |
|
300 |
|
|
301 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
302 |
|
|
303 |
void setSizeChangeType(SizeChangeEffect.Type type) |
|
304 |
{ |
|
305 |
mSizeChangeType = type; |
|
306 |
} |
|
307 |
|
|
308 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
309 |
|
|
310 |
void setSolveType(SolveEffect.Type type) |
|
280 |
void setPos(int index, int pos) |
|
311 | 281 |
{ |
312 |
mSolveType = type;
|
|
282 |
if( index>=0 && index<RubikSettingsEnum.LENGTH ) mPos[index] = pos;
|
|
313 | 283 |
} |
314 | 284 |
|
315 | 285 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
316 | 286 |
|
317 |
void setScrambleType(ScrambleEffect.Type type)
|
|
287 |
void setType(int index, int type)
|
|
318 | 288 |
{ |
319 |
mScrambleType = type;
|
|
289 |
if( index>=0 && index<RubikSettingsEnum.LENGTH ) mType[index] = type;
|
|
320 | 290 |
} |
321 | 291 |
|
322 | 292 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
380 | 350 |
{ |
381 | 351 |
try |
382 | 352 |
{ |
383 |
ScrambleEffect effect = ScrambleEffect.create(mScrambleType);
|
|
384 |
mScrambleEffectID = effect.start(mScrambleDuration,mNewCube,mScrambleCubeNum,this);
|
|
353 |
ScrambleEffect effect = ScrambleEffect.create(mType[2]);
|
|
354 |
mScrambleEffectID = effect.start(mPos[2],mNewCube,mScrambleCubeNum,this);
|
|
385 | 355 |
} |
386 | 356 |
catch(Exception ex) |
387 | 357 |
{ |
... | ... | |
408 | 378 |
{ |
409 | 379 |
try |
410 | 380 |
{ |
411 |
SolveEffect effect = SolveEffect.create(mSolveType);
|
|
412 |
mSolveEffectID = effect.start(mSolveDuration,mScreen,mNewCube,this);
|
|
381 |
SolveEffect effect = SolveEffect.create(mType[1]);
|
|
382 |
mSolveEffectID = effect.start(mPos[1],mScreen,mNewCube,this);
|
|
413 | 383 |
} |
414 | 384 |
catch(Exception ex) |
415 | 385 |
{ |
src/main/java/org/distorted/magic/RubikSettings.java | ||
---|---|---|
44 | 44 |
{ |
45 | 45 |
public interface OnCompleteListener |
46 | 46 |
{ |
47 |
void onComplete(int sizeP, int solvP, int scraP, int sizeT, int solvT, int scraT);
|
|
47 |
void onComplete(int index, int position, int type);
|
|
48 | 48 |
} |
49 | 49 |
|
50 | 50 |
private OnCompleteListener mListener; |
... | ... | |
293 | 293 |
|
294 | 294 |
private void saveOptions() |
295 | 295 |
{ |
296 |
mListener.onComplete(mPos[0], mPos[1], mPos[2], mType[0], mType[1], mType[2]); |
|
296 |
for (int i=0; i<RubikSettingsEnum.LENGTH; i++) |
|
297 |
{ |
|
298 |
mListener.onComplete(i, mPos[i], mType[i]); |
|
299 |
} |
|
297 | 300 |
} |
298 | 301 |
|
299 | 302 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
RubikCube: major progress with a separate RubikSettingsEnum enum - has been introduced into RubikActivity & RubikRenderer.