Revision b498f3f6
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/dialog/RubikDialogPattern.java | ||
|---|---|---|
| 37 | 37 |
import android.widget.TextView; |
| 38 | 38 |
|
| 39 | 39 |
import org.distorted.magic.R; |
| 40 |
import org.distorted.patterns.RubikPattern; |
|
| 40 |
import org.distorted.object.RubikObjectList; |
|
| 41 |
import org.distorted.patterns.RubikPatternList; |
|
| 41 | 42 |
|
| 42 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 43 | 44 |
|
| ... | ... | |
| 94 | 95 |
tabLayout.setupWithViewPager(viewPager); |
| 95 | 96 |
viewPager.setCurrentItem(curTab); |
| 96 | 97 |
|
| 97 |
int[] iconID = { R.drawable.cube2, R.drawable.cube3, R.drawable.cube4, R.drawable.cube5 };
|
|
| 98 |
|
|
| 99 |
for(int i=0; i< RubikPattern.NUM_CUBES; i++) |
|
| 98 |
for(int i=0; i< RubikPatternList.NUM_OBJECTS; i++) |
|
| 100 | 99 |
{
|
| 100 |
RubikObjectList list = RubikPatternList.getObject(i); |
|
| 101 |
int size = RubikPatternList.getSize(i); |
|
| 102 |
int sizeIndex = RubikObjectList.getSizeIndex(list.ordinal(),size); |
|
| 103 |
int iconID = list.getIconIDs()[sizeIndex]; |
|
| 104 |
|
|
| 101 | 105 |
ImageView imageView = new ImageView(act); |
| 102 |
imageView.setImageResource(iconID[i]);
|
|
| 106 |
imageView.setImageResource(iconID); |
|
| 103 | 107 |
TabLayout.Tab tab = tabLayout.getTabAt(i); |
| 104 | 108 |
if(tab!=null) tab.setCustomView(imageView); |
| 105 | 109 |
} |
| src/main/java/org/distorted/dialog/RubikDialogPatternPagerAdapter.java | ||
|---|---|---|
| 27 | 27 |
import android.view.ViewGroup; |
| 28 | 28 |
|
| 29 | 29 |
import org.distorted.patterns.RubikPattern; |
| 30 |
import org.distorted.patterns.RubikPatternList; |
|
| 30 | 31 |
|
| 31 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 32 | 33 |
|
| ... | ... | |
| 43 | 44 |
{
|
| 44 | 45 |
mAct = act; |
| 45 | 46 |
mDialog = dialog; |
| 46 |
mNumTabs = RubikPattern.NUM_CUBES;
|
|
| 47 |
mNumTabs = RubikPatternList.NUM_OBJECTS;
|
|
| 47 | 48 |
mViews = new RubikDialogPatternView[mNumTabs]; |
| 48 | 49 |
|
| 49 | 50 |
viewPager.setAdapter(this); |
| src/main/java/org/distorted/dialog/RubikDialogPatternView.java | ||
|---|---|---|
| 36 | 36 |
import org.distorted.magic.RubikActivity; |
| 37 | 37 |
import org.distorted.object.RubikObjectList; |
| 38 | 38 |
import org.distorted.patterns.RubikPattern; |
| 39 |
import org.distorted.patterns.RubikPatternList; |
|
| 39 | 40 |
import org.distorted.uistate.RubikState; |
| 40 | 41 |
import org.distorted.uistate.RubikStatePattern; |
| 41 | 42 |
|
| ... | ... | |
| 153 | 154 |
@Override |
| 154 | 155 |
public void onClick(View view) |
| 155 | 156 |
{
|
| 156 |
int[] sizes = RubikObjectList.CUBE.getSizes(); |
|
| 157 | 157 |
int[][] moves = pattern.reInitialize(mTab, category, ii); |
| 158 |
act.changeObject(RubikObjectList.CUBE,sizes[mTab],moves); |
|
| 158 |
|
|
| 159 |
RubikObjectList list = RubikPatternList.getObject(mTab); |
|
| 160 |
int size = RubikPatternList.getSize(mTab); |
|
| 161 |
|
|
| 162 |
act.changeObject( list, size, moves); |
|
| 163 |
|
|
| 159 | 164 |
RubikStatePattern state = (RubikStatePattern) RubikState.PATT.getStateClass(); |
| 160 | 165 |
state.setPattern(act, mTab, category, ii); |
| 161 | 166 |
mDialog.rememberState(); |
| src/main/java/org/distorted/object/RubikObjectList.java | ||
|---|---|---|
| 85 | 85 |
|
| 86 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 87 | 87 |
|
| 88 |
public static int pack(int object, int size) |
|
| 88 |
public static int pack(int object, int sizeIndex)
|
|
| 89 | 89 |
{
|
| 90 | 90 |
int ret = 0; |
| 91 | 91 |
for(int i=0; i<object; i++) ret += objects[i].mObjectSizes.length; |
| 92 | 92 |
|
| 93 |
return ret+size; |
|
| 93 |
return ret+sizeIndex;
|
|
| 94 | 94 |
} |
| 95 | 95 |
|
| 96 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/patterns/RubikPattern.java | ||
|---|---|---|
| 20 | 20 |
package org.distorted.patterns; |
| 21 | 21 |
|
| 22 | 22 |
import org.distorted.magic.RubikPostRender; |
| 23 |
import org.distorted.object.RubikObject; |
|
| 24 | 23 |
|
| 25 | 24 |
import java.util.ArrayList; |
| 26 | 25 |
import java.util.List; |
| 27 | 26 |
|
| 27 |
import static org.distorted.patterns.RubikPatternList.NUM_OBJECTS; |
|
| 28 |
|
|
| 28 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 29 | 30 |
|
| 30 | 31 |
public class RubikPattern |
| 31 | 32 |
{
|
| 32 | 33 |
private static final int DURATION_MILLIS = 800; |
| 33 | 34 |
|
| 34 |
public static final int MIN_CUBE = 2; |
|
| 35 |
public static final int MAX_CUBE = 5; |
|
| 36 |
public static final int NUM_CUBES = MAX_CUBE-MIN_CUBE+1; |
|
| 37 |
|
|
| 38 |
private int[] numCategories = new int[NUM_CUBES]; |
|
| 39 |
private int[] currentCategory = new int[NUM_CUBES]; |
|
| 40 |
private int[] currentScrollPos= new int[NUM_CUBES]; |
|
| 35 |
private int[] numCategories = new int[NUM_OBJECTS]; |
|
| 36 |
private int[] currentCategory = new int[NUM_OBJECTS]; |
|
| 37 |
private int[] currentScrollPos= new int[NUM_OBJECTS]; |
|
| 41 | 38 |
|
| 42 | 39 |
private List<List<Category>> mCategories; |
| 43 | 40 |
private static RubikPattern mThis; |
| ... | ... | |
| 55 | 52 |
|
| 56 | 53 |
Category(String[] lines) |
| 57 | 54 |
{
|
| 58 |
mLines=lines; |
|
| 59 |
numPatterns=lines.length-1; |
|
| 60 |
mPatterns = new ArrayList<>(); |
|
| 55 |
mLines = lines; |
|
| 56 |
numPatterns = lines.length-1; |
|
| 61 | 57 |
mInitialized = false; |
| 62 | 58 |
} |
| 63 | 59 |
|
| ... | ... | |
| 69 | 65 |
String moves, name; |
| 70 | 66 |
Pattern pattern; |
| 71 | 67 |
|
| 68 |
mPatterns = new ArrayList<>(); |
|
| 69 |
|
|
| 72 | 70 |
for(int i=0; i<numPatterns; i++) |
| 73 | 71 |
{
|
| 74 | 72 |
colon = mLines[i+1].indexOf(":");
|
| ... | ... | |
| 204 | 202 |
|
| 205 | 203 |
///////////////////////////////////////////////////////////// |
| 206 | 204 |
|
| 207 |
Pattern(String n, String m)
|
|
| 205 |
Pattern(String name, String moves)
|
|
| 208 | 206 |
{
|
| 209 |
nameStr = n;
|
|
| 210 |
moveStr = m;
|
|
| 207 |
nameStr = name;
|
|
| 208 |
moveStr = moves;
|
|
| 211 | 209 |
mCanRotate = true; |
| 212 | 210 |
mInitialized = false; |
| 213 | 211 |
} |
| ... | ... | |
| 269 | 267 |
if( !mInitialized ) initialize(); |
| 270 | 268 |
|
| 271 | 269 |
curMove++; |
| 272 |
RubikObject object = post.getObject(); |
|
| 273 | 270 |
|
| 274 | 271 |
if( mCanRotate ) |
| 275 | 272 |
{
|
| ... | ... | |
| 280 | 277 |
} |
| 281 | 278 |
else |
| 282 | 279 |
{
|
| 283 |
int axis =moves[curMove-1][0]; |
|
| 284 |
int rowBitmap=moves[curMove-1][1]; |
|
| 285 |
int bareAngle=moves[curMove-1][2]; |
|
| 286 |
int angle = bareAngle*(360/object.getBasicAngle());
|
|
| 280 |
int axis = moves[curMove-1][0];
|
|
| 281 |
int rowBitmap= moves[curMove-1][1];
|
|
| 282 |
int bareAngle= moves[curMove-1][2];
|
|
| 283 |
int angle = bareAngle*(360/post.getObject().getBasicAngle());
|
|
| 287 | 284 |
int numRot = Math.abs(bareAngle); |
| 288 | 285 |
|
| 289 | 286 |
if( angle!=0 ) |
| ... | ... | |
| 311 | 308 |
if( !mInitialized ) initialize(); |
| 312 | 309 |
|
| 313 | 310 |
curMove--; |
| 314 |
RubikObject object = post.getObject(); |
|
| 315 | 311 |
|
| 316 | 312 |
if( mCanRotate ) |
| 317 | 313 |
{
|
| ... | ... | |
| 322 | 318 |
} |
| 323 | 319 |
else |
| 324 | 320 |
{
|
| 325 |
int axis =moves[curMove][0]; |
|
| 326 |
int rowBitmap=moves[curMove][1]; |
|
| 327 |
int bareAngle=moves[curMove][2]; |
|
| 328 |
int angle = bareAngle*(360/object.getBasicAngle());
|
|
| 321 |
int axis = moves[curMove][0];
|
|
| 322 |
int rowBitmap= moves[curMove][1];
|
|
| 323 |
int bareAngle= moves[curMove][2];
|
|
| 324 |
int angle = bareAngle*(360/post.getObject().getBasicAngle());
|
|
| 329 | 325 |
int numRot = Math.abs(bareAngle); |
| 330 | 326 |
|
| 331 | 327 |
if( angle!=0 ) |
| ... | ... | |
| 371 | 367 |
{
|
| 372 | 368 |
mCategories = new ArrayList<>(); |
| 373 | 369 |
|
| 374 |
initializeCategories(0, RubikPatternCube2.patterns); |
|
| 375 |
initializeCategories(1, RubikPatternCube3.patterns); |
|
| 376 |
initializeCategories(2, RubikPatternCube4.patterns); |
|
| 377 |
initializeCategories(3, RubikPatternCube5.patterns); |
|
| 370 |
for(int i=0; i<NUM_OBJECTS; i++) |
|
| 371 |
{
|
|
| 372 |
List<Category> list = new ArrayList<>(); |
|
| 373 |
String[][] patStrings = RubikPatternList.getPatterns(i); |
|
| 374 |
|
|
| 375 |
for(String[] lines: patStrings) list.add(new Category(lines)); |
|
| 376 |
|
|
| 377 |
mCategories.add(list); |
|
| 378 |
numCategories[i]=patStrings.length; |
|
| 379 |
} |
|
| 378 | 380 |
} |
| 379 | 381 |
|
| 380 | 382 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 381 | 383 |
|
| 382 |
private void initializeCategories(int num, String[][] pat)
|
|
| 384 |
private Category getCategory(int tab, int cat)
|
|
| 383 | 385 |
{
|
| 384 |
List<Category> list = new ArrayList<>(); |
|
| 385 |
Category cat; |
|
| 386 |
|
|
| 387 |
for(String[] lines: pat) |
|
| 386 |
if( tab>=0 && tab<NUM_OBJECTS && cat>=0 && cat<numCategories[tab] ) |
|
| 388 | 387 |
{
|
| 389 |
cat = new Category(lines); |
|
| 390 |
list.add(cat); |
|
| 388 |
return mCategories.get(tab).get(cat); |
|
| 391 | 389 |
} |
| 392 | 390 |
|
| 393 |
mCategories.add(num,list); |
|
| 394 |
numCategories[num]=pat.length; |
|
| 391 |
return null; |
|
| 395 | 392 |
} |
| 396 | 393 |
|
| 397 | 394 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 412 | 409 |
|
| 413 | 410 |
public int getNumCategories(int tab) |
| 414 | 411 |
{
|
| 415 |
return tab>=0 && tab<NUM_CUBES ? numCategories[tab] : 0; |
|
| 416 |
} |
|
| 417 |
|
|
| 418 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 419 |
|
|
| 420 |
public String getCategoryName(int tab, int cat) |
|
| 421 |
{
|
|
| 422 |
if( tab>=0 && tab<NUM_CUBES && cat>=0 && cat< numCategories[tab] ) |
|
| 423 |
{
|
|
| 424 |
Category c = mCategories.get(tab).get(cat); |
|
| 425 |
return c!=null ? c.getName() : null; |
|
| 426 |
} |
|
| 427 |
|
|
| 428 |
return null; |
|
| 412 |
return tab>=0 && tab<NUM_OBJECTS ? numCategories[tab] : 0; |
|
| 429 | 413 |
} |
| 430 | 414 |
|
| 431 | 415 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 432 | 416 |
|
| 433 | 417 |
public void rememberState(int tab, int cat, int scrollPos) |
| 434 | 418 |
{
|
| 435 |
if( tab>=0 && tab<NUM_CUBES )
|
|
| 419 |
if( tab>=0 && tab<NUM_OBJECTS )
|
|
| 436 | 420 |
{
|
| 437 | 421 |
currentCategory[tab] = cat; |
| 438 | 422 |
currentScrollPos[tab]= scrollPos; |
| ... | ... | |
| 443 | 427 |
|
| 444 | 428 |
public int recallCategory(int tab) |
| 445 | 429 |
{
|
| 446 |
return tab>=0 && tab<NUM_CUBES ? currentCategory[tab] : 0;
|
|
| 430 |
return tab>=0 && tab<NUM_OBJECTS ? currentCategory[tab] : 0;
|
|
| 447 | 431 |
} |
| 448 | 432 |
|
| 449 | 433 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 450 | 434 |
|
| 451 | 435 |
public int recallScrollPos(int tab) |
| 452 | 436 |
{
|
| 453 |
return tab>=0 && tab<NUM_CUBES ? currentScrollPos[tab] : 0;
|
|
| 437 |
return tab>=0 && tab<NUM_OBJECTS ? currentScrollPos[tab] : 0;
|
|
| 454 | 438 |
} |
| 455 | 439 |
|
| 456 | 440 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 457 | 441 |
|
| 458 |
public String getPatternName(int tab, int cat, int pat)
|
|
| 442 |
public String getCategoryName(int tab, int cat)
|
|
| 459 | 443 |
{
|
| 460 |
if( tab>=0 && tab<NUM_CUBES && cat>=0 && cat< numCategories[tab] ) |
|
| 461 |
{
|
|
| 462 |
Category c = mCategories.get(tab).get(cat); |
|
| 463 |
return c!=null ? c.getPatternName(pat) : null; |
|
| 464 |
} |
|
| 444 |
Category c = getCategory(tab,cat); |
|
| 445 |
return c!=null ? c.getName() : null; |
|
| 446 |
} |
|
| 465 | 447 |
|
| 466 |
return null; |
|
| 448 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 449 |
|
|
| 450 |
public String getPatternName(int tab, int cat, int pat) |
|
| 451 |
{
|
|
| 452 |
Category c = getCategory(tab,cat); |
|
| 453 |
return c!=null ? c.getPatternName(pat) : null; |
|
| 467 | 454 |
} |
| 468 | 455 |
|
| 469 | 456 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 470 | 457 |
|
| 471 | 458 |
public int getNumPatterns(int tab, int cat) |
| 472 | 459 |
{
|
| 473 |
if( tab>=0 && tab<NUM_CUBES && cat>=0 && cat< numCategories[tab] ) |
|
| 474 |
{
|
|
| 475 |
Category c = mCategories.get(tab).get(cat); |
|
| 476 |
return c!=null ? c.getNumPatterns() : 0; |
|
| 477 |
} |
|
| 478 |
|
|
| 479 |
return 0; |
|
| 460 |
Category c = getCategory(tab,cat); |
|
| 461 |
return c!=null ? c.getNumPatterns() : 0; |
|
| 480 | 462 |
} |
| 481 | 463 |
|
| 482 | 464 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 483 | 465 |
|
| 484 | 466 |
public int getCurMove(int tab, int cat, int pat) |
| 485 | 467 |
{
|
| 486 |
if( tab>=0 && tab<NUM_CUBES && cat>=0 && cat< numCategories[tab] ) |
|
| 487 |
{
|
|
| 488 |
Category c = mCategories.get(tab).get(cat); |
|
| 489 |
return c!=null ? c.getPatternCurMove(pat):0; |
|
| 490 |
} |
|
| 491 |
|
|
| 492 |
return 0; |
|
| 468 |
Category c = getCategory(tab,cat); |
|
| 469 |
return c!=null ? c.getPatternCurMove(pat) : 0; |
|
| 493 | 470 |
} |
| 494 | 471 |
|
| 495 | 472 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 496 | 473 |
|
| 497 | 474 |
public int getNumMoves(int tab, int cat, int pat) |
| 498 | 475 |
{
|
| 499 |
if( tab>=0 && tab<NUM_CUBES && cat>=0 && cat< numCategories[tab] ) |
|
| 500 |
{
|
|
| 501 |
Category c = mCategories.get(tab).get(cat); |
|
| 502 |
return c!=null ? c.getPatternNumMove(pat):0; |
|
| 503 |
} |
|
| 504 |
|
|
| 505 |
return 0; |
|
| 476 |
Category c = getCategory(tab,cat); |
|
| 477 |
return c!=null ? c.getPatternNumMove(pat) : 0; |
|
| 506 | 478 |
} |
| 507 | 479 |
|
| 508 | 480 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 509 | 481 |
|
| 510 | 482 |
public void makeMove(RubikPostRender post, int tab, int cat, int pat) |
| 511 | 483 |
{
|
| 512 |
if( tab>=0 && tab<NUM_CUBES && cat>=0 && cat< numCategories[tab] ) |
|
| 513 |
{
|
|
| 514 |
Category c = mCategories.get(tab).get(cat); |
|
| 515 |
if( c!=null ) c.makeMove(post,pat); |
|
| 516 |
} |
|
| 484 |
Category c = getCategory(tab,cat); |
|
| 485 |
if( c!=null ) c.makeMove(post,pat); |
|
| 517 | 486 |
} |
| 518 | 487 |
|
| 519 | 488 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 520 | 489 |
|
| 521 | 490 |
public void backMove(RubikPostRender post, int tab, int cat, int pat) |
| 522 | 491 |
{
|
| 523 |
if( tab>=0 && tab<NUM_CUBES && cat>=0 && cat< numCategories[tab] ) |
|
| 524 |
{
|
|
| 525 |
Category c = mCategories.get(tab).get(cat); |
|
| 526 |
if( c!=null ) c.backMove(post,pat); |
|
| 527 |
} |
|
| 492 |
Category c = getCategory(tab,cat); |
|
| 493 |
if( c!=null ) c.backMove(post,pat); |
|
| 528 | 494 |
} |
| 529 | 495 |
|
| 530 | 496 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 531 | 497 |
|
| 532 | 498 |
public int[][] reInitialize(int tab, int cat, int pat) |
| 533 | 499 |
{
|
| 534 |
if( tab>=0 && tab<NUM_CUBES && cat>=0 && cat< numCategories[tab] ) |
|
| 535 |
{
|
|
| 536 |
Category c = mCategories.get(tab).get(cat); |
|
| 537 |
if( c!=null ) return c.reInitialize(pat); |
|
| 538 |
} |
|
| 539 |
|
|
| 540 |
return null; |
|
| 500 |
Category c = getCategory(tab,cat); |
|
| 501 |
return c!=null ? c.reInitialize(pat) : null; |
|
| 541 | 502 |
} |
| 542 | 503 |
} |
| src/main/java/org/distorted/patterns/RubikPatternList.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.patterns; |
|
| 21 |
|
|
| 22 |
import org.distorted.object.RubikObjectList; |
|
| 23 |
|
|
| 24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 25 |
|
|
| 26 |
public enum RubikPatternList |
|
| 27 |
{
|
|
| 28 |
CUBE2 (RubikObjectList.CUBE, 2, RubikPatternCube2.patterns), |
|
| 29 |
CUBE3 (RubikObjectList.CUBE, 3, RubikPatternCube3.patterns), |
|
| 30 |
CUBE4 (RubikObjectList.CUBE, 4, RubikPatternCube4.patterns), |
|
| 31 |
CUBE5 (RubikObjectList.CUBE, 5, RubikPatternCube5.patterns), |
|
| 32 |
; |
|
| 33 |
|
|
| 34 |
public static final int NUM_OBJECTS = values().length; |
|
| 35 |
private RubikObjectList mObject; |
|
| 36 |
private int mSize; |
|
| 37 |
private String[][] mPatterns; |
|
| 38 |
|
|
| 39 |
private static final RubikPatternList[] objects; |
|
| 40 |
|
|
| 41 |
static |
|
| 42 |
{
|
|
| 43 |
objects = new RubikPatternList[NUM_OBJECTS]; |
|
| 44 |
int i=0; |
|
| 45 |
|
|
| 46 |
for(RubikPatternList object: RubikPatternList.values()) |
|
| 47 |
{
|
|
| 48 |
objects[i++] = object; |
|
| 49 |
} |
|
| 50 |
} |
|
| 51 |
|
|
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 53 |
|
|
| 54 |
static RubikPatternList[] getPatterns() |
|
| 55 |
{
|
|
| 56 |
return objects; |
|
| 57 |
} |
|
| 58 |
|
|
| 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 60 |
|
|
| 61 |
static String[][] getPatterns(int ordinal) |
|
| 62 |
{
|
|
| 63 |
return objects[ordinal].mPatterns; |
|
| 64 |
} |
|
| 65 |
|
|
| 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 67 |
|
|
| 68 |
RubikPatternList(RubikObjectList object, int size, String[][] patterns) |
|
| 69 |
{
|
|
| 70 |
mObject = object; |
|
| 71 |
mSize = size; |
|
| 72 |
mPatterns = patterns; |
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
// PUBLIC API |
|
| 77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 78 |
|
|
| 79 |
public static int getOrdinal(int objectOrdinal, int size) |
|
| 80 |
{
|
|
| 81 |
for(int i=0; i<NUM_OBJECTS; i++) |
|
| 82 |
{
|
|
| 83 |
if( objects[i].mObject.ordinal() == objectOrdinal && objects[i].mSize == size ) |
|
| 84 |
{
|
|
| 85 |
return i; |
|
| 86 |
} |
|
| 87 |
} |
|
| 88 |
|
|
| 89 |
return -1; |
|
| 90 |
} |
|
| 91 |
|
|
| 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 93 |
|
|
| 94 |
public static RubikObjectList getObject(int ordinal) |
|
| 95 |
{
|
|
| 96 |
return objects[ordinal].mObject; |
|
| 97 |
} |
|
| 98 |
|
|
| 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 100 |
|
|
| 101 |
public static int getSize(int ordinal) |
|
| 102 |
{
|
|
| 103 |
return objects[ordinal].mSize; |
|
| 104 |
} |
|
| 105 |
} |
|
| src/main/java/org/distorted/uistate/RubikStatePattern.java | ||
|---|---|---|
| 37 | 37 |
import org.distorted.magic.RubikPostRender; |
| 38 | 38 |
import org.distorted.object.RubikObjectList; |
| 39 | 39 |
import org.distorted.patterns.RubikPattern; |
| 40 |
import org.distorted.patterns.RubikPatternList; |
|
| 40 | 41 |
|
| 41 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 42 | 43 |
|
| 43 | 44 |
public class RubikStatePattern extends RubikStateAbstract |
| 44 | 45 |
{
|
| 45 |
// TODO: read this from upper_text.xml; this is the height of the TextView there. |
|
| 46 |
private static final int DEFAULT_TEXT_SIZE = 30; |
|
| 47 |
|
|
| 48 | 46 |
private TextView mText; |
| 49 | 47 |
private Button mBackButton; |
| 50 | 48 |
private ImageButton mPrevButton, mNextButton; |
| 51 | 49 |
private TextView mMovesText; |
| 52 | 50 |
private int mNumMoves; |
| 53 |
private int mSizeIndex, mCategory, mPattern;
|
|
| 51 |
private int mPatternOrdinal, mCategory, mPattern;
|
|
| 54 | 52 |
|
| 55 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 56 | 54 |
|
| ... | ... | |
| 64 | 62 |
void leaveState(RubikActivity act) |
| 65 | 63 |
{
|
| 66 | 64 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass(); |
| 67 |
int s = RubikObjectList.CUBE.getSizes()[mSizeIndex]; |
|
| 68 | 65 |
|
| 69 |
if( !play.setObjectAndSize(RubikObjectList.CUBE, s) ) |
|
| 66 |
RubikObjectList object = RubikPatternList.getObject(mPatternOrdinal); |
|
| 67 |
int size = RubikPatternList.getSize(mPatternOrdinal); |
|
| 68 |
|
|
| 69 |
if( !play.setObjectAndSize(object,size) ) |
|
| 70 | 70 |
{
|
| 71 |
int object= play.getObject(); |
|
| 72 |
int size = play.getSize(); |
|
| 71 |
int objectPlay= play.getObject();
|
|
| 72 |
int sizePlay = play.getSize();
|
|
| 73 | 73 |
|
| 74 |
act.changeObject(RubikObjectList.getObject(object),size,null);
|
|
| 74 |
act.changeObject(RubikObjectList.getObject(objectPlay),sizePlay,null);
|
|
| 75 | 75 |
} |
| 76 | 76 |
} |
| 77 | 77 |
|
| ... | ... | |
| 83 | 83 |
int obj = play.getObject(); |
| 84 | 84 |
int size = play.getSize(); |
| 85 | 85 |
|
| 86 |
if( size>=RubikPattern.MIN_CUBE && size<=RubikPattern.MAX_CUBE && obj==RubikObjectList.CUBE.ordinal() ) |
|
| 87 |
{
|
|
| 88 |
mSizeIndex = RubikObjectList.getSizeIndex(obj,size); |
|
| 89 |
} |
|
| 90 |
else |
|
| 86 |
mPatternOrdinal = RubikPatternList.getOrdinal(obj,size); |
|
| 87 |
|
|
| 88 |
if( mPatternOrdinal<0 ) |
|
| 91 | 89 |
{
|
| 92 |
mSizeIndex = RubikObjectList.getSizeIndex(RubikObjectList.CUBE.ordinal(),RubikStatePlay.DEF_SIZE);
|
|
| 93 |
act.changeObject(RubikObjectList.CUBE,RubikStatePlay.DEF_SIZE,null);
|
|
| 90 |
mPatternOrdinal = RubikObjectList.getSizeIndex(RubikStatePlay.DEF_OBJECT,RubikStatePlay.DEF_SIZE);
|
|
| 91 |
act.changeObject(RubikObjectList.getObject(RubikStatePlay.DEF_OBJECT),RubikStatePlay.DEF_SIZE,null);
|
|
| 94 | 92 |
} |
| 95 | 93 |
|
| 96 | 94 |
FragmentManager mana = act.getSupportFragmentManager(); |
| ... | ... | |
| 132 | 130 |
|
| 133 | 131 |
private void showDialog(FragmentManager manager) |
| 134 | 132 |
{
|
| 135 |
Bundle bundle = new Bundle(); |
|
| 136 |
int object = RubikObjectList.CUBE.ordinal(); |
|
| 137 |
bundle.putInt("tab", RubikObjectList.pack(object,mSizeIndex) );
|
|
| 138 |
|
|
| 139 | 133 |
RubikDialogPattern diag = new RubikDialogPattern(); |
| 134 |
Bundle bundle = new Bundle(); |
|
| 135 |
bundle.putInt("tab", mPatternOrdinal );
|
|
| 140 | 136 |
diag.setArguments(bundle); |
| 141 | 137 |
diag.show( manager, RubikDialogPattern.getDialogTag() ); |
| 142 | 138 |
} |
| ... | ... | |
| 162 | 158 |
|
| 163 | 159 |
if( diag==null ) |
| 164 | 160 |
{
|
| 165 |
mText.setTextSize(DEFAULT_TEXT_SIZE); |
|
| 166 | 161 |
showDialog(mana); |
| 167 | 162 |
} |
| 168 | 163 |
else |
| ... | ... | |
| 193 | 188 |
{
|
| 194 | 189 |
RubikPattern pattern = RubikPattern.getInstance(); |
| 195 | 190 |
RubikPostRender post = act.getPostRender(); |
| 196 |
pattern.backMove( post, mSizeIndex, mCategory, mPattern);
|
|
| 197 |
int currMove = pattern.getCurMove(mSizeIndex, mCategory, mPattern);
|
|
| 191 |
pattern.backMove( post, mPatternOrdinal, mCategory, mPattern);
|
|
| 192 |
int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
|
|
| 198 | 193 |
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves)); |
| 199 | 194 |
} |
| 200 | 195 |
}); |
| ... | ... | |
| 218 | 213 |
{
|
| 219 | 214 |
RubikPattern pattern = RubikPattern.getInstance(); |
| 220 | 215 |
RubikPostRender post = act.getPostRender(); |
| 221 |
pattern.makeMove( post, mSizeIndex, mCategory, mPattern);
|
|
| 222 |
int currMove = pattern.getCurMove(mSizeIndex, mCategory, mPattern);
|
|
| 216 |
pattern.makeMove( post, mPatternOrdinal, mCategory, mPattern);
|
|
| 217 |
int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
|
|
| 223 | 218 |
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves)); |
| 224 | 219 |
} |
| 225 | 220 |
}); |
| ... | ... | |
| 239 | 234 |
mMovesText.setGravity(Gravity.CENTER); |
| 240 | 235 |
|
| 241 | 236 |
RubikPattern pattern = RubikPattern.getInstance(); |
| 242 |
int currMove = pattern.getCurMove(mSizeIndex, mCategory, mPattern);
|
|
| 237 |
int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
|
|
| 243 | 238 |
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves)); |
| 244 | 239 |
} |
| 245 | 240 |
|
| 246 | 241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 247 | 242 |
|
| 248 |
public void setPattern(final RubikActivity act, int sizeIndex, int category, int pattern)
|
|
| 243 |
public void setPattern(final RubikActivity act, int ordinal, int category, int pattern)
|
|
| 249 | 244 |
{
|
| 250 |
mSizeIndex = sizeIndex;
|
|
| 251 |
mCategory = category; |
|
| 252 |
mPattern = pattern; |
|
| 245 |
mPatternOrdinal = ordinal;
|
|
| 246 |
mCategory = category;
|
|
| 247 |
mPattern = pattern;
|
|
| 253 | 248 |
|
| 254 | 249 |
RubikPattern patt = RubikPattern.getInstance(); |
| 255 |
String patternName = patt.getPatternName(sizeIndex,category,pattern);
|
|
| 250 |
String patternName = patt.getPatternName(ordinal,category,pattern);
|
|
| 256 | 251 |
mText.setText(patternName); |
| 257 | 252 |
|
| 258 |
mNumMoves = patt.getNumMoves(sizeIndex,category,pattern);
|
|
| 259 |
int currMove= patt.getCurMove(sizeIndex,category,pattern);
|
|
| 253 |
mNumMoves = patt.getNumMoves(ordinal,category,pattern);
|
|
| 254 |
int currMove= patt.getCurMove(ordinal,category,pattern);
|
|
| 260 | 255 |
|
| 261 | 256 |
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves)); |
| 262 | 257 |
} |
Also available in: Unified diff
Introduce RubikPatternsList. Now, if one wants to contribute patterns for a new object, all one has to be is give the list of strings describing the patterns and add them to the List.