Revision aa171dee
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/dialog/RubikDialogPatternView.java | ||
---|---|---|
150 | 150 |
public void onClick(View view) |
151 | 151 |
{ |
152 | 152 |
RubikStatePattern state = (RubikStatePattern) RubikState.PATT.getStateClass(); |
153 |
state.setPattern(mTab, category, ii); |
|
153 |
state.setPattern(act, mTab, category, ii);
|
|
154 | 154 |
int[] sizes = RubikObjectList.CUBE.getSizes(); |
155 |
act.changeObject(RubikObjectList.CUBE,sizes[mTab]); |
|
155 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
156 |
String moves = pattern.getMoves(mTab, category, ii); |
|
157 |
act.changeObject(RubikObjectList.CUBE,sizes[mTab],moves); |
|
156 | 158 |
mDialog.rememberCategories(); |
157 | 159 |
mDialog.dismiss(); |
158 | 160 |
} |
src/main/java/org/distorted/magic/RubikActivity.java | ||
---|---|---|
31 | 31 |
import org.distorted.effect.BaseEffect; |
32 | 32 |
import org.distorted.library.main.DistortedLibrary; |
33 | 33 |
|
34 |
import org.distorted.object.RubikObject; |
|
34 | 35 |
import org.distorted.scores.RubikScores; |
35 | 36 |
import org.distorted.scores.RubikScoresDownloader; |
36 | 37 |
import org.distorted.object.RubikObjectList; |
... | ... | |
101 | 102 |
if( sizeIndex>=0 && sizeIndex<sizes.length ) |
102 | 103 |
{ |
103 | 104 |
success = true; |
104 |
view.getRenderer().createObject( obj, size );
|
|
105 |
view.getRenderer().changeObject( obj, size, null );
|
|
105 | 106 |
} |
106 | 107 |
|
107 | 108 |
} |
... | ... | |
112 | 113 |
int s = RubikStatePlay.DEF_SIZE; |
113 | 114 |
|
114 | 115 |
play.setObjectAndSize(obj,s); |
115 |
view.getRenderer().createObject(obj,s);
|
|
116 |
view.getRenderer().changeObject(obj,s, null);
|
|
116 | 117 |
} |
117 | 118 |
} |
118 | 119 |
|
... | ... | |
175 | 176 |
// PUBLIC API |
176 | 177 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
177 | 178 |
|
178 |
public void changeObject(RubikObjectList object, int size) |
|
179 |
public RubikObject getObject() |
|
180 |
{ |
|
181 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
182 |
RubikRenderer renderer = view.getRenderer(); |
|
183 |
return renderer.getObject(); |
|
184 |
} |
|
185 |
|
|
186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
187 |
|
|
188 |
public void changeObject(RubikObjectList object, int size, String moves) |
|
179 | 189 |
{ |
180 | 190 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
181 | 191 |
RubikRenderer renderer = view.getRenderer(); |
182 | 192 |
|
183 | 193 |
if( renderer.canDrag() ) |
184 | 194 |
{ |
185 |
renderer.createObject(object,size);
|
|
195 |
renderer.changeObject(object,size,moves);
|
|
186 | 196 |
} |
187 | 197 |
} |
188 | 198 |
|
src/main/java/org/distorted/magic/RubikRenderer.java | ||
---|---|---|
61 | 61 |
private RubikObject mOldObject, mNewObject; |
62 | 62 |
private int mScreenWidth, mScreenHeight; |
63 | 63 |
private SharedPreferences mPreferences; |
64 |
private String mNextMoves; |
|
64 | 65 |
|
65 | 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
66 | 67 |
|
... | ... | |
92 | 93 |
|
93 | 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
94 | 95 |
|
95 |
private void createObjectNow(RubikObjectList object, int size) |
|
96 |
private void createObjectNow(RubikObjectList object, int size, String moves)
|
|
96 | 97 |
{ |
97 | 98 |
boolean firstTime = (mNewObject==null); |
98 | 99 |
|
99 | 100 |
if( mOldObject!=null ) mOldObject.releaseResources(); |
100 | 101 |
mOldObject = mNewObject; |
101 | 102 |
|
102 |
mNewObject = object.create(size, mView.getQuatCurrent(), mView.getQuatAccumulated()); |
|
103 |
mNewObject = object.create(size, mView.getQuatCurrent(), mView.getQuatAccumulated(), moves);
|
|
103 | 104 |
mNewObject.createTexture(); |
104 | 105 |
mView.setMovement(object.getObjectMovementClass()); |
105 | 106 |
|
... | ... | |
161 | 162 |
|
162 | 163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
163 | 164 |
|
164 |
void createObject(RubikObjectList object, int size)
|
|
165 |
void changeObject(RubikObjectList object, int size, String moves)
|
|
165 | 166 |
{ |
166 |
if( (object!=mNextObject || mNextSize!=size) && size>0 )
|
|
167 |
if( size>0 ) |
|
167 | 168 |
{ |
168 | 169 |
mChangeObject = true; |
169 | 170 |
mNextObject = object; |
170 | 171 |
mNextSize = size; |
172 |
mNextMoves = moves; |
|
171 | 173 |
} |
172 | 174 |
} |
173 | 175 |
|
... | ... | |
192 | 194 |
} |
193 | 195 |
} |
194 | 196 |
|
195 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
196 |
|
|
197 |
void setCanRotate(boolean can) |
|
198 |
{ |
|
199 |
mCanRotate = can; |
|
200 |
} |
|
201 |
|
|
202 | 197 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
203 | 198 |
|
204 | 199 |
boolean canRotate() |
... | ... | |
307 | 302 |
mCanDrag = false; |
308 | 303 |
mCanRotate = false; |
309 | 304 |
mCanUI = false; |
310 |
createObjectNow(mNextObject, mNextSize); |
|
311 |
doEffectNow( BaseEffect.Type.SIZECHANGE ); |
|
305 |
|
|
306 |
if( mNewObject==null ) |
|
307 |
{ |
|
308 |
createObjectNow(mNextObject, mNextSize, mNextMoves); |
|
309 |
doEffectNow( BaseEffect.Type.SIZECHANGE ); |
|
310 |
} |
|
311 |
else |
|
312 |
{ |
|
313 |
RubikObjectList list = mNewObject.getObjectList(); |
|
314 |
int size = mNewObject.getSize(); |
|
315 |
|
|
316 |
if (list!=mNextObject || mNextSize!=size) |
|
317 |
{ |
|
318 |
createObjectNow(mNextObject, mNextSize, mNextMoves); |
|
319 |
doEffectNow( BaseEffect.Type.SIZECHANGE ); |
|
320 |
} |
|
321 |
else |
|
322 |
{ |
|
323 |
mNewObject.initializeObject(mNextMoves); |
|
324 |
} |
|
325 |
} |
|
312 | 326 |
} |
313 | 327 |
|
314 | 328 |
if( mSolveObject ) |
src/main/java/org/distorted/object/RubikCube.java | ||
---|---|---|
78 | 78 |
|
79 | 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
80 | 80 |
|
81 |
RubikCube(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects) |
|
81 |
RubikCube(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects, String moves)
|
|
82 | 82 |
{ |
83 |
super(size, 60, quatCur,quatAcc,texture,mesh,effects); |
|
83 |
super(size, 60, quatCur,quatAcc,texture,mesh,effects,moves, RubikObjectList.CUBE);
|
|
84 | 84 |
} |
85 | 85 |
|
86 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/object/RubikObject.java | ||
---|---|---|
60 | 60 |
private Static4D mQuatAccumulated; |
61 | 61 |
private Cubit[] mCubits; |
62 | 62 |
private int mSize; |
63 |
private RubikObjectList mList; |
|
63 | 64 |
|
64 | 65 |
float mStart, mStep; |
65 | 66 |
|
... | ... | |
73 | 74 |
|
74 | 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
75 | 76 |
|
76 |
RubikObject(int size, int fov, Static4D quatCur, Static4D quatAcc, DistortedTexture nodeTexture, MeshRectangles nodeMesh, DistortedEffects nodeEffects) |
|
77 |
RubikObject(int size, int fov, Static4D quatCur, Static4D quatAcc, DistortedTexture nodeTexture, |
|
78 |
MeshRectangles nodeMesh, DistortedEffects nodeEffects, String moves, RubikObjectList list) |
|
77 | 79 |
{ |
78 | 80 |
super(nodeTexture,nodeEffects,nodeMesh); |
79 | 81 |
|
80 | 82 |
resizeFBO(NODE_FBO_SIZE, NODE_FBO_SIZE); |
81 | 83 |
|
84 |
mList = list; |
|
82 | 85 |
mOrigPos = getCubitPositions(size); |
83 | 86 |
|
84 | 87 |
LEGAL_QUATS = getLegalQuats(); |
... | ... | |
122 | 125 |
attach(mCubits[i].mNode); |
123 | 126 |
} |
124 | 127 |
|
128 |
setupPosition(moves); |
|
129 |
|
|
125 | 130 |
setProjection(fov, 0.1f); |
126 | 131 |
} |
127 | 132 |
|
... | ... | |
214 | 219 |
rotationAngle.add(mRotationAngleFinal); |
215 | 220 |
} |
216 | 221 |
|
222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
223 |
// TODO |
|
224 |
|
|
225 |
private boolean scheduleMultiRotation(int rotV, int rotRC, int rotA) |
|
226 |
{ |
|
227 |
/* |
|
228 |
int index, tmp; |
|
229 |
|
|
230 |
if( numRotations>0 ) |
|
231 |
{ |
|
232 |
if( rotVector!=rotV ) return false; |
|
233 |
|
|
234 |
index=0; |
|
235 |
tmp=rotRC; |
|
236 |
|
|
237 |
while( tmp!=0 ) |
|
238 |
{ |
|
239 |
if( (tmp&0x1)==1 && rotAngle[index]!=0 ) return false; |
|
240 |
index++; |
|
241 |
tmp/=2; |
|
242 |
} |
|
243 |
} |
|
244 |
|
|
245 |
index=0; |
|
246 |
tmp=rotRC; |
|
247 |
rotVector = rotV; |
|
248 |
|
|
249 |
while( tmp!=0 ) |
|
250 |
{ |
|
251 |
if( (tmp&0x1)==1 ) |
|
252 |
{ |
|
253 |
rotAngle[index] = rotA*90; |
|
254 |
rotSpeed[index] = (int)(rotS/RubikWorld.hardwareSpeed); |
|
255 |
|
|
256 |
if( rotSpeed[index]<=0 && rotS>0 ) rotSpeed[index] = 1; |
|
257 |
if( rotSpeed[index]>=0 && rotS<0 ) rotSpeed[index] =-1; |
|
258 |
|
|
259 |
numRotations++; |
|
260 |
} |
|
261 |
|
|
262 |
index++; |
|
263 |
tmp/=2; |
|
264 |
} |
|
265 |
*/ |
|
266 |
return true; |
|
267 |
} |
|
268 |
|
|
269 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
270 |
// TODO |
|
271 |
|
|
272 |
private void setupPosition(String moves) |
|
273 |
{ |
|
274 |
android.util.Log.e("object", "initializing: "+moves); |
|
275 |
/* |
|
276 |
int index,tmp, a1,a2,a3, rv, rc, ra; |
|
277 |
|
|
278 |
numRotations=0; |
|
279 |
initializeVertices(mSize); |
|
280 |
|
|
281 |
int len=moves.length()/4; |
|
282 |
|
|
283 |
for(int i=0; i<len; i++) |
|
284 |
{ |
|
285 |
a1=moves.charAt(4*i+1)-'0'; |
|
286 |
a2=moves.charAt(4*i+2)-'0'; |
|
287 |
a3=moves.charAt(4*i+3)-'0'; |
|
288 |
|
|
289 |
rv = (10*a1+a2)/32; |
|
290 |
rc = (10*a1+a2)%32; |
|
291 |
ra = 2-a3; |
|
292 |
|
|
293 |
rotVector = rv; |
|
294 |
|
|
295 |
tmp=rc; |
|
296 |
index=0; |
|
297 |
|
|
298 |
while( tmp!=0 ) |
|
299 |
{ |
|
300 |
if( (tmp&0x1)==1 ) |
|
301 |
{ |
|
302 |
rotAngle[index] = ra*90; |
|
303 |
RubikWorld.setIdentity(rotMat[index]); |
|
304 |
|
|
305 |
switch(rotVector) |
|
306 |
{ |
|
307 |
case VECTX: RubikWorld.postRotate( rotMat[index], (float)((ra*90)%360), 1f,0f,0f); break; |
|
308 |
case VECTY: RubikWorld.postRotate( rotMat[index], (float)((ra*90)%360), 0f,1f,0f); break; |
|
309 |
case VECTZ: RubikWorld.postRotate( rotMat[index], (float)((ra*90)%360), 0f,0f,1f); break; |
|
310 |
} |
|
311 |
|
|
312 |
transposeTiles(index); |
|
313 |
rotAngle[index]=0; |
|
314 |
} |
|
315 |
|
|
316 |
tmp/=2; |
|
317 |
index++; |
|
318 |
} |
|
319 |
} |
|
320 |
*/ |
|
321 |
} |
|
322 |
|
|
217 | 323 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
218 | 324 |
// Clamp all rotated positions to one of those original ones to avoid accumulating errors. |
219 | 325 |
|
... | ... | |
461 | 567 |
mRotationAngleStatic.set0(0); |
462 | 568 |
} |
463 | 569 |
|
570 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
571 |
|
|
572 |
public boolean makeMove(String move) |
|
573 |
{ |
|
574 |
int a1=move.charAt(1)-'0'; |
|
575 |
int a2=move.charAt(2)-'0'; |
|
576 |
int a3=move.charAt(3)-'0'; |
|
577 |
|
|
578 |
int rotVector = (10*a1+a2)/32; // 0 --> VECTX, 1--> VECTY, 2 --> VECTZ |
|
579 |
int rotBitmap = (10*a1+a2)%32; // 01010 --> move the 2nd and 4th layer |
|
580 |
int rotAngle = 2-a3; // counterclockwise by rotAngle*90 degrees |
|
581 |
|
|
582 |
return scheduleMultiRotation(rotVector, rotBitmap, rotAngle); |
|
583 |
} |
|
584 |
|
|
585 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
586 |
|
|
587 |
public boolean backMove(String move) |
|
588 |
{ |
|
589 |
int a1=move.charAt(1)-'0'; |
|
590 |
int a2=move.charAt(2)-'0'; |
|
591 |
int a3=move.charAt(3)-'0'; |
|
592 |
|
|
593 |
int rotVector = (10*a1+a2)/32; |
|
594 |
int rotBitmap = (10*a1+a2)%32; |
|
595 |
int rotAngle = a3-2; |
|
596 |
|
|
597 |
return scheduleMultiRotation(rotVector, rotBitmap, rotAngle); |
|
598 |
} |
|
599 |
|
|
600 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
601 |
|
|
602 |
public void initializeObject(String moves) |
|
603 |
{ |
|
604 |
solve(); |
|
605 |
setupPosition(moves); |
|
606 |
} |
|
607 |
|
|
608 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
609 |
|
|
610 |
public RubikObjectList getObjectList() |
|
611 |
{ |
|
612 |
return mList; |
|
613 |
} |
|
614 |
|
|
464 | 615 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
465 | 616 |
|
466 | 617 |
abstract float getScreenRatio(); |
src/main/java/org/distorted/object/RubikObjectList.java | ||
---|---|---|
245 | 245 |
|
246 | 246 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
247 | 247 |
|
248 |
public RubikObject create(int size, Static4D quatCur, Static4D quatAcc) |
|
248 |
public RubikObject create(int size, Static4D quatCur, Static4D quatAcc, String moves)
|
|
249 | 249 |
{ |
250 | 250 |
DistortedTexture texture = new DistortedTexture(); |
251 | 251 |
DistortedEffects effects = new DistortedEffects(); |
... | ... | |
253 | 253 |
|
254 | 254 |
switch(ordinal()) |
255 | 255 |
{ |
256 |
case 0: return new RubikCube (size, quatCur, quatAcc, texture, mesh, effects); |
|
257 |
case 1: return new RubikPyraminx(size, quatCur, quatAcc, texture, mesh, effects); |
|
256 |
case 0: return new RubikCube (size, quatCur, quatAcc, texture, mesh, effects, moves);
|
|
257 |
case 1: return new RubikPyraminx(size, quatCur, quatAcc, texture, mesh, effects, moves);
|
|
258 | 258 |
} |
259 | 259 |
|
260 | 260 |
return null; |
src/main/java/org/distorted/object/RubikPyraminx.java | ||
---|---|---|
83 | 83 |
|
84 | 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
85 | 85 |
|
86 |
RubikPyraminx(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects) |
|
86 |
RubikPyraminx(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects, String moves)
|
|
87 | 87 |
{ |
88 |
super(size, 30, quatCur,quatAcc,texture,mesh,effects); |
|
88 |
super(size, 30, quatCur,quatAcc,texture,mesh,effects,moves, RubikObjectList.PYRA);
|
|
89 | 89 |
} |
90 | 90 |
|
91 | 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/patterns/RubikPattern.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.patterns; |
21 | 21 |
|
22 |
import org.distorted.object.RubikObject; |
|
23 |
|
|
22 | 24 |
import java.util.Vector; |
23 | 25 |
|
24 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
111 | 113 |
|
112 | 114 |
///////////////////////////////////////////////////////////// |
113 | 115 |
|
114 |
String retInitializationString(int pattern)
|
|
116 |
void makeMove(RubikObject object, int pattern)
|
|
115 | 117 |
{ |
116 | 118 |
if( pattern>=0 && pattern<numPatterns ) |
117 | 119 |
{ |
118 | 120 |
Pattern p = patterns.elementAt(pattern); |
119 |
if( p!=null ) return p.retInitializationString();
|
|
121 |
if( p!=null ) p.makeMove(object);
|
|
120 | 122 |
} |
121 |
|
|
122 |
return ""; |
|
123 | 123 |
} |
124 | 124 |
|
125 | 125 |
///////////////////////////////////////////////////////////// |
126 | 126 |
|
127 |
String retNextMove(int pattern)
|
|
127 |
void backMove(RubikObject object, int pattern)
|
|
128 | 128 |
{ |
129 | 129 |
if( pattern>=0 && pattern<numPatterns ) |
130 | 130 |
{ |
131 | 131 |
Pattern p = patterns.elementAt(pattern); |
132 |
if( p!=null ) return p.retNextMove();
|
|
132 |
if( p!=null ) p.backMove(object);
|
|
133 | 133 |
} |
134 |
|
|
135 |
return ""; |
|
136 | 134 |
} |
137 | 135 |
|
138 | 136 |
///////////////////////////////////////////////////////////// |
139 | 137 |
|
140 |
String retPrevMove(int pattern)
|
|
138 |
String getMoves(int pattern)
|
|
141 | 139 |
{ |
142 | 140 |
if( pattern>=0 && pattern<numPatterns ) |
143 | 141 |
{ |
144 | 142 |
Pattern p = patterns.elementAt(pattern); |
145 |
if( p!=null ) return p.retPrevMove();
|
|
143 |
if( p!=null ) return p.getMoves();
|
|
146 | 144 |
} |
147 | 145 |
|
148 | 146 |
return ""; |
... | ... | |
191 | 189 |
|
192 | 190 |
///////////////////////////////////////////////////////////// |
193 | 191 |
|
194 |
String retNextMove()
|
|
192 |
void makeMove(RubikObject object)
|
|
195 | 193 |
{ |
196 | 194 |
curMove++; |
197 | 195 |
|
198 | 196 |
if( curMove>numMove) |
199 | 197 |
{ |
200 | 198 |
curMove= 0; |
201 |
return retInitializationString();
|
|
199 |
object.initializeObject(moves.substring(0,4*curMove));
|
|
202 | 200 |
} |
203 | 201 |
else |
204 | 202 |
{ |
205 |
curMove--; |
|
206 |
return moves.substring(4*curMove-4,4*curMove); |
|
203 |
if( !object.makeMove(moves.substring(4*curMove-4,4*curMove)) ) |
|
204 |
{ |
|
205 |
curMove--; |
|
206 |
} |
|
207 | 207 |
} |
208 | 208 |
} |
209 | 209 |
|
210 | 210 |
///////////////////////////////////////////////////////////// |
211 | 211 |
|
212 |
String retPrevMove()
|
|
212 |
void backMove(RubikObject object)
|
|
213 | 213 |
{ |
214 | 214 |
curMove--; |
215 | 215 |
|
216 | 216 |
if( curMove<0) |
217 | 217 |
{ |
218 | 218 |
curMove=numMove; |
219 |
return retInitializationString();
|
|
219 |
object.initializeObject(moves.substring(0,4*curMove));
|
|
220 | 220 |
} |
221 | 221 |
else |
222 | 222 |
{ |
223 |
curMove++; |
|
224 |
return moves.substring(4*curMove,4*curMove+4); |
|
223 |
if( !object.backMove(moves.substring(4*curMove,4*curMove+4)) ) |
|
224 |
{ |
|
225 |
curMove++; |
|
226 |
} |
|
225 | 227 |
} |
226 | 228 |
} |
227 | 229 |
|
228 | 230 |
///////////////////////////////////////////////////////////// |
229 | 231 |
|
230 |
String retInitializationString()
|
|
232 |
String getMoves()
|
|
231 | 233 |
{ |
232 | 234 |
return moves.substring(0,4*curMove); |
233 | 235 |
} |
... | ... | |
382 | 384 |
|
383 | 385 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
384 | 386 |
|
385 |
public String retNextMove(int size, int cat, int pat)
|
|
387 |
public void makeMove(RubikObject object, int size, int cat, int pat)
|
|
386 | 388 |
{ |
387 | 389 |
if( size>=0 && size<NUM_CUBES && cat>=0 && cat< numCategories[size] ) |
388 | 390 |
{ |
389 | 391 |
Category c = mCategories[size].elementAt(cat); |
390 |
if( c!=null ) return c.retNextMove(pat);
|
|
392 |
if( c!=null ) c.makeMove(object,pat);
|
|
391 | 393 |
} |
392 |
|
|
393 |
return ""; |
|
394 | 394 |
} |
395 | 395 |
|
396 | 396 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
397 | 397 |
|
398 |
public String retPrevMove(int size, int cat, int pat)
|
|
398 |
public void backMove(RubikObject object, int size, int cat, int pat)
|
|
399 | 399 |
{ |
400 | 400 |
if( size>=0 && size<NUM_CUBES && cat>=0 && cat< numCategories[size] ) |
401 | 401 |
{ |
402 | 402 |
Category c = mCategories[size].elementAt(cat); |
403 |
if( c!=null ) return c.retPrevMove(pat);
|
|
403 |
if( c!=null ) c.backMove(object,pat);
|
|
404 | 404 |
} |
405 |
|
|
406 |
return ""; |
|
407 | 405 |
} |
408 | 406 |
|
409 | 407 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
410 | 408 |
|
411 |
public String retInitializationString(int size,int cat, int pat)
|
|
409 |
public String getMoves(int size, int cat, int pat)
|
|
412 | 410 |
{ |
413 | 411 |
if( size>=0 && size<NUM_CUBES && cat>=0 && cat< numCategories[size] ) |
414 | 412 |
{ |
415 | 413 |
Category c = mCategories[size].elementAt(cat); |
416 |
if( c!=null ) return c.retInitializationString(pat);
|
|
414 |
if( c!=null ) return c.getMoves(pat);
|
|
417 | 415 |
} |
418 | 416 |
|
419 | 417 |
return ""; |
src/main/java/org/distorted/uistate/RubikStatePattern.java | ||
---|---|---|
34 | 34 |
import org.distorted.dialog.RubikDialogPattern; |
35 | 35 |
import org.distorted.magic.R; |
36 | 36 |
import org.distorted.magic.RubikActivity; |
37 |
import org.distorted.object.RubikObject; |
|
37 | 38 |
import org.distorted.object.RubikObjectList; |
38 | 39 |
import org.distorted.patterns.RubikPattern; |
39 | 40 |
|
... | ... | |
48 | 49 |
private Button mBackButton; |
49 | 50 |
private ImageButton mPrevButton, mNextButton; |
50 | 51 |
private TextView mMovesText; |
51 |
private int mSize; |
|
52 |
private int mNumMoves, mCurrMove; |
|
53 |
private int mSizeIndex, mCategory, mPattern; |
|
52 | 54 |
|
53 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
54 | 56 |
|
... | ... | |
62 | 64 |
void leaveState(RubikActivity act) |
63 | 65 |
{ |
64 | 66 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass(); |
67 |
int s = RubikObjectList.CUBE.getSizes()[mSizeIndex]; |
|
65 | 68 |
|
66 |
if( !play.setObjectAndSize(RubikObjectList.CUBE, mSize) )
|
|
69 |
if( !play.setObjectAndSize(RubikObjectList.CUBE, s) )
|
|
67 | 70 |
{ |
68 | 71 |
int object= play.getObject(); |
69 | 72 |
int size = play.getSize(); |
70 | 73 |
|
71 |
act.changeObject(RubikObjectList.getObject(object),size); |
|
74 |
act.changeObject(RubikObjectList.getObject(object),size,null);
|
|
72 | 75 |
} |
73 | 76 |
} |
74 | 77 |
|
... | ... | |
82 | 85 |
|
83 | 86 |
if( size>=RubikPattern.MIN_CUBE && size<=RubikPattern.MAX_CUBE && obj==RubikObjectList.CUBE.ordinal() ) |
84 | 87 |
{ |
85 |
mSize = size;
|
|
88 |
mSizeIndex = RubikObjectList.getSizeIndex(obj,size);
|
|
86 | 89 |
} |
87 | 90 |
else |
88 | 91 |
{ |
89 |
mSize = RubikStatePlay.DEF_SIZE;
|
|
90 |
act.changeObject(RubikObjectList.CUBE,mSize);
|
|
92 |
mSizeIndex = RubikObjectList.getSizeIndex(RubikObjectList.CUBE.ordinal(),RubikStatePlay.DEF_SIZE);
|
|
93 |
act.changeObject(RubikObjectList.CUBE,RubikStatePlay.DEF_SIZE,null);
|
|
91 | 94 |
} |
92 | 95 |
|
93 | 96 |
FragmentManager mana = act.getSupportFragmentManager(); |
... | ... | |
131 | 134 |
{ |
132 | 135 |
Bundle bundle = new Bundle(); |
133 | 136 |
int object = RubikObjectList.CUBE.ordinal(); |
134 |
int sizeIndex = RubikObjectList.getSizeIndex(object,mSize); |
|
135 |
bundle.putInt("tab", RubikObjectList.pack(object,sizeIndex) ); |
|
137 |
bundle.putInt("tab", RubikObjectList.pack(object,mSizeIndex) ); |
|
136 | 138 |
|
137 | 139 |
RubikDialogPattern diag = new RubikDialogPattern(); |
138 | 140 |
diag.setArguments(bundle); |
... | ... | |
190 | 192 |
@Override |
191 | 193 |
public void onClick(View v) |
192 | 194 |
{ |
193 |
android.util.Log.e("patt", "prev button clicked!"); |
|
195 |
if( --mCurrMove< 0 ) mCurrMove=mNumMoves; |
|
196 |
|
|
197 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves)); |
|
198 |
RubikObject object = act.getObject(); |
|
199 |
RubikPattern.getInstance().backMove( object, mSizeIndex, mCategory, mPattern); |
|
194 | 200 |
} |
195 | 201 |
}); |
196 | 202 |
} |
... | ... | |
211 | 217 |
@Override |
212 | 218 |
public void onClick(View v) |
213 | 219 |
{ |
214 |
android.util.Log.e("patt", "next button clicked!"); |
|
220 |
if( ++mCurrMove> mNumMoves ) mCurrMove=0; |
|
221 |
|
|
222 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves)); |
|
223 |
RubikObject object = act.getObject(); |
|
224 |
RubikPattern.getInstance().makeMove( object, mSizeIndex, mCategory, mPattern); |
|
215 | 225 |
} |
216 | 226 |
}); |
217 | 227 |
} |
... | ... | |
224 | 234 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f); |
225 | 235 |
|
226 | 236 |
mMovesText = new TextView(act); |
237 |
mMovesText.setTextSize(20); |
|
227 | 238 |
mMovesText.setLayoutParams(params); |
228 | 239 |
mMovesText.setPadding(padding,0,padding,0); |
229 | 240 |
mMovesText.setGravity(Gravity.CENTER); |
230 | 241 |
|
231 |
mMovesText.setText("aaa");
|
|
242 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves));
|
|
232 | 243 |
} |
233 | 244 |
|
234 | 245 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
235 | 246 |
|
236 |
public void setPattern(int sizeIndex, int category, int pattern) |
|
247 |
public void setPattern(final RubikActivity act, int sizeIndex, int category, int pattern)
|
|
237 | 248 |
{ |
238 |
mSize = RubikObjectList.CUBE.getSizes()[sizeIndex]; |
|
249 |
mSizeIndex = sizeIndex; |
|
250 |
mCategory = category; |
|
251 |
mPattern = pattern; |
|
239 | 252 |
|
240 | 253 |
RubikPattern patt = RubikPattern.getInstance(); |
241 | 254 |
String patternName = patt.getPatternName(sizeIndex,category,pattern); |
242 | 255 |
mText.setText(patternName); |
256 |
|
|
257 |
mNumMoves = patt.getNumMoves(sizeIndex,category,pattern); |
|
258 |
mCurrMove = patt.getCurMove(sizeIndex,category,pattern); |
|
259 |
|
|
260 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves)); |
|
243 | 261 |
} |
244 | 262 |
|
245 | 263 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/uistate/RubikStatePlay.java | ||
---|---|---|
197 | 197 |
{ |
198 | 198 |
mObject = obj; |
199 | 199 |
mSize = sizes[size]; |
200 |
act.changeObject(list,sizes[size]); |
|
200 |
act.changeObject(list,sizes[size],null);
|
|
201 | 201 |
mPopup.dismiss(); |
202 | 202 |
} |
203 | 203 |
}); |
src/main/res/values/strings.xml | ||
---|---|---|
41 | 41 |
<string name="tm_placeholder">%1$02d:%2$02d</string> |
42 | 42 |
<string name="ap_placeholder">%1$s %2$s</string> |
43 | 43 |
<string name="ti_placeholder">%1$.1f seconds</string> |
44 |
<string name="mo_placeholder">%1$d/%2$d</string> |
|
44 | 45 |
</resources> |
Also available in: Unified diff
More support for actual patterns!