Revision 8ab435b9
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/screens/RubikScreenPlay.java | ||
---|---|---|
54 | 54 |
{ |
55 | 55 |
public static final int NUM_COLUMNS = 4; |
56 | 56 |
public static final int LEVELS_SHOWN = 10; |
57 |
public static final int DEF_OBJECT= ObjectType.CUBE_3.ordinal(); |
|
57 |
public static int MAX_LEVEL; |
|
58 |
public static final ObjectType DEF_OBJECT= ObjectType.CUBE_3; |
|
58 | 59 |
|
59 | 60 |
private static final int[] BUTTON_LABELS = { R.string.scores, |
60 | 61 |
R.string.patterns, |
... | ... | |
70 | 71 |
private ImageButton mObjButton, mMenuButton, mSolveButton; |
71 | 72 |
private Button mPlayButton; |
72 | 73 |
private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup; |
73 |
private int mObject = DEF_OBJECT;
|
|
74 |
private ObjectType mObject = DEF_OBJECT;
|
|
74 | 75 |
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth; |
75 | 76 |
private int mLevelValue; |
76 | 77 |
private float mButtonSize, mMenuItemSize, mMenuTextSize; |
... | ... | |
78 | 79 |
private LinearLayout mPlayLayout; |
79 | 80 |
private int mUpperBarHeight; |
80 | 81 |
|
82 |
static |
|
83 |
{ |
|
84 |
ObjectType[] types = ObjectType.values(); |
|
85 |
int max = Integer.MIN_VALUE; |
|
86 |
|
|
87 |
for (ObjectType type : types) |
|
88 |
{ |
|
89 |
int cur = getDBLevel(type); |
|
90 |
if( cur>max ) max = cur; |
|
91 |
} |
|
92 |
|
|
93 |
MAX_LEVEL = max; |
|
94 |
} |
|
95 |
|
|
81 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
82 | 97 |
|
83 | 98 |
void leaveScreen(RubikActivity act) |
... | ... | |
120 | 135 |
createBottomPane(act,width,mSolveButton); |
121 | 136 |
} |
122 | 137 |
|
123 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
138 |
////////////////////////////////////////////////////////////////////////////////////////////////// |
|
124 | 139 |
|
125 | 140 |
private void setupObjectButton(final RubikActivity act, final float width) |
126 | 141 |
{ |
... | ... | |
163 | 178 |
{ |
164 | 179 |
View popupView = mPlayPopup.getContentView(); |
165 | 180 |
popupView.setSystemUiVisibility(RubikActivity.FLAGS); |
166 |
final int dbLevel = ObjectType.getDBLevel(mObject);
|
|
181 |
final int dbLevel = getDBLevel(mObject); |
|
167 | 182 |
final int levelsShown = Math.min(dbLevel,LEVELS_SHOWN); |
168 | 183 |
final int popupHeight = (int)(levelsShown*(mMenuItemSize+margin)+3*margin+mMenuItemSize*(LAST_BUTTON-1.0f)); |
169 | 184 |
final int realHeight = Math.min(popupHeight,maxHeight); |
... | ... | |
258 | 273 |
{ |
259 | 274 |
if( act.getPreRender().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY ) |
260 | 275 |
{ |
261 |
mObject = obj;
|
|
276 |
mObject = ObjectType.getObject(obj);
|
|
262 | 277 |
act.changeObject(list, true); |
263 | 278 |
adjustLevels(act); |
264 | 279 |
mMovesController.clearMoves(act); |
... | ... | |
344 | 359 |
{ |
345 | 360 |
switch(button) |
346 | 361 |
{ |
347 |
case 0: RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass(); |
|
348 |
int object = play.getObject(); |
|
349 |
Bundle sBundle = new Bundle(); |
|
350 |
sBundle.putInt("tab", object ); |
|
362 |
case 0: Bundle sBundle = new Bundle(); |
|
363 |
sBundle.putInt("tab", mObject.ordinal() ); |
|
351 | 364 |
sBundle.putBoolean("submitting", false); |
352 | 365 |
RubikDialogScores scores = new RubikDialogScores(); |
353 | 366 |
scores.setArguments(sBundle); |
... | ... | |
403 | 416 |
|
404 | 417 |
public void savePreferences(SharedPreferences.Editor editor) |
405 | 418 |
{ |
406 |
editor.putInt("statePlay_object", mObject);
|
|
419 |
editor.putString("statePlay_objName", mObject.name() );
|
|
407 | 420 |
|
408 | 421 |
if( mObjectPopup!=null ) |
409 | 422 |
{ |
... | ... | |
428 | 441 |
|
429 | 442 |
public void restorePreferences(SharedPreferences preferences) |
430 | 443 |
{ |
431 |
mObject= preferences.getInt("statePlay_object", DEF_OBJECT); |
|
432 |
int dbLevel = ObjectType.getDBLevel(mObject); |
|
433 |
|
|
434 |
// This means the app has been upgraded to a new version which swapped the |
|
435 |
// Object for a new one with larger sizeIndex and now getMaxLevel() returns |
|
436 |
// 0. Reset the object to default, otherwise we'll get a crash later on. |
|
437 |
|
|
438 |
if( dbLevel==0 ) mObject = DEF_OBJECT; |
|
444 |
String objName= preferences.getString("statePlay_objName", DEF_OBJECT.name() ); |
|
445 |
int ordinal = ObjectType.getOrdinal(objName); |
|
446 |
mObject = ordinal>=0 ? ObjectType.values()[ordinal] : DEF_OBJECT; |
|
439 | 447 |
} |
440 | 448 |
|
441 | 449 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
442 | 450 |
|
443 | 451 |
public boolean setObject(RubikActivity act, ObjectType obj) |
444 | 452 |
{ |
445 |
if( mObject!=obj.ordinal() )
|
|
453 |
if( mObject!=obj ) |
|
446 | 454 |
{ |
447 |
mObject = obj.ordinal();
|
|
455 |
mObject = obj; |
|
448 | 456 |
if( mPlayLayout!=null ) adjustLevels(act); |
449 | 457 |
return true; |
450 | 458 |
} |
... | ... | |
493 | 501 |
|
494 | 502 |
private void adjustLevels(final RubikActivity act) |
495 | 503 |
{ |
496 |
int dbLevel = ObjectType.getDBLevel(mObject);
|
|
497 |
int numScrambles = ObjectType.getNumScramble(mObject); |
|
504 |
int dbLevel = getDBLevel(mObject); |
|
505 |
int numScrambles = ObjectType.getNumScramble(mObject.ordinal());
|
|
498 | 506 |
int numLevel = Math.min(dbLevel, LEVELS_SHOWN); |
499 | 507 |
String[] levels = new String[numLevel]; |
500 | 508 |
|
... | ... | |
541 | 549 |
button.setText(levels[i]); |
542 | 550 |
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize); |
543 | 551 |
|
544 |
int icon = scores.isSolved(mObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved; |
|
552 |
int icon = scores.isSolved(mObject.ordinal(), level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
|
545 | 553 |
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0); |
546 | 554 |
|
547 | 555 |
button.setOnClickListener( new View.OnClickListener() |
... | ... | |
564 | 572 |
} |
565 | 573 |
} |
566 | 574 |
|
575 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
576 |
// historically older versions of the app had lower 'maxScrambles' in case of several objects and |
|
577 |
// those got remembered in the server-side DB already, so we need to keep using them. This function |
|
578 |
// provides a map between 'maxScramble' of an object and its 'dbLevel'. All new objects will have |
|
579 |
// those two values the same. |
|
580 |
|
|
581 |
public static int getDBLevel(ObjectType object) |
|
582 |
{ |
|
583 |
switch(object) |
|
584 |
{ |
|
585 |
case CUBE_3: return 16; |
|
586 |
case CUBE_4: return 20; |
|
587 |
case CUBE_5: return 24; |
|
588 |
case PYRA_4: return 14; |
|
589 |
case PYRA_5: return 20; |
|
590 |
case MEGA_5: return 35; |
|
591 |
case DIAM_2: return 10; |
|
592 |
case DIAM_3: return 18; |
|
593 |
case REDI_3: return 14; |
|
594 |
case HELI_3: return 18; |
|
595 |
case SKEW_3: return 17; |
|
596 |
case REX_3 : return 16; |
|
597 |
case MIRR_3: return 16; |
|
598 |
default : return ObjectType.getNumScramble(object.ordinal()); |
|
599 |
} |
|
600 |
} |
|
601 |
|
|
567 | 602 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
568 | 603 |
|
569 | 604 |
public int getLevel() |
... | ... | |
573 | 608 |
|
574 | 609 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
575 | 610 |
|
576 |
public int getObject()
|
|
611 |
public ObjectType getObject()
|
|
577 | 612 |
{ |
578 | 613 |
return mObject; |
579 | 614 |
} |
Also available in: Unified diff
1. Remove 'db level' from objectlib (this belongs to the app!)
2. change ScreenPlay's 'mObject' to be an ObjectType.