Revision d433b50e
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/screens/RubikScreenPlay.java | ||
---|---|---|
35 | 35 |
import android.widget.LinearLayout; |
36 | 36 |
import android.widget.PopupWindow; |
37 | 37 |
|
38 |
import org.distorted.objectlib.main.ObjectConstants; |
|
38 | 39 |
import org.distorted.objectlib.main.ObjectControl; |
39 |
import org.distorted.objectlib.main.ObjectType; |
|
40 | 40 |
|
41 | 41 |
import org.distorted.main.R; |
42 | 42 |
import org.distorted.main.RubikActivity; |
... | ... | |
47 | 47 |
import org.distorted.helpers.TransparentButton; |
48 | 48 |
import org.distorted.helpers.TransparentImageButton; |
49 | 49 |
import org.distorted.network.RubikScores; |
50 |
import org.distorted.objects.RubikObject; |
|
51 |
import org.distorted.objects.RubikObjectList; |
|
50 | 52 |
|
51 | 53 |
import static android.view.View.inflate; |
52 |
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS; |
|
53 | 54 |
|
54 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 | 56 |
|
... | ... | |
57 | 58 |
{ |
58 | 59 |
public static final int NUM_COLUMNS = 4; |
59 | 60 |
public static final int LEVELS_SHOWN = 10; |
60 |
public static int MAX_LEVEL; |
|
61 |
public static final ObjectType DEF_OBJECT= ObjectType.CUBE_3; |
|
61 |
public static final int DEF_OBJECT= ObjectConstants.CUBE_3; |
|
62 | 62 |
|
63 | 63 |
private static final int[] BUTTON_LABELS = { R.string.scores, |
64 | 64 |
R.string.patterns, |
... | ... | |
73 | 73 |
private TransparentImageButton mObjButton, mMenuButton, mSolveButton, mScrambleButton; |
74 | 74 |
private TransparentButton mPlayButton; |
75 | 75 |
private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup; |
76 |
private ObjectType mObject = DEF_OBJECT;
|
|
76 |
private int mObject = DEF_OBJECT;
|
|
77 | 77 |
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth; |
78 | 78 |
private int mLevelValue; |
79 | 79 |
private float mButtonSize, mMenuItemSize, mMenuTextSize; |
... | ... | |
82 | 82 |
private int mUpperBarHeight; |
83 | 83 |
private boolean mShouldReactToEndOfScrambling; |
84 | 84 |
|
85 |
static |
|
86 |
{ |
|
87 |
ObjectType[] types = ObjectType.values(); |
|
88 |
int max = Integer.MIN_VALUE; |
|
89 |
|
|
90 |
for (ObjectType type : types) |
|
91 |
{ |
|
92 |
int cur = getDBLevel(type); |
|
93 |
if( cur>max ) max = cur; |
|
94 |
} |
|
95 |
|
|
96 |
MAX_LEVEL = max; |
|
97 |
} |
|
98 |
|
|
99 | 85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
100 | 86 |
|
101 | 87 |
void leaveScreen(RubikActivity act) |
... | ... | |
107 | 93 |
|
108 | 94 |
void enterScreen(final RubikActivity act) |
109 | 95 |
{ |
96 |
int numObjects = RubikObjectList.getNumObjects(); |
|
110 | 97 |
float width = act.getScreenWidthInPixels(); |
111 | 98 |
mUpperBarHeight = act.getHeightUpperBar(); |
112 | 99 |
|
... | ... | |
114 | 101 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
115 | 102 |
mMenuItemSize = width*RubikActivity.MENU_ITEM_SIZE; |
116 | 103 |
|
117 |
mRowCount = (NUM_OBJECTS + NUM_COLUMNS-1) / NUM_COLUMNS;
|
|
104 |
mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
|
|
118 | 105 |
mColCount = NUM_COLUMNS; |
119 | 106 |
|
120 | 107 |
// TOP //////////////////////////// |
... | ... | |
192 | 179 |
final int maxHeight= (int)(0.9f*(height-mUpperBarHeight) ); |
193 | 180 |
View popupView = mPlayPopup.getContentView(); |
194 | 181 |
popupView.setSystemUiVisibility(RubikActivity.FLAGS); |
195 |
final int dbLevel = getDBLevel(mObject); |
|
182 |
final int dbLevel = RubikObjectList.getDBLevel(mObject);
|
|
196 | 183 |
final int levelsShown = Math.min(dbLevel,LEVELS_SHOWN); |
197 | 184 |
final int popupHeight = (int)(levelsShown*(mMenuItemSize+margin)+3*margin+mMenuItemSize*(LAST_BUTTON-1.0f)); |
198 | 185 |
final int realHeight = Math.min(popupHeight,maxHeight); |
... | ... | |
255 | 242 |
objectGrid.setRowCount(mRowCount); |
256 | 243 |
|
257 | 244 |
LinearLayout bottomLayout = view.findViewById(R.id.bottomLayout); |
258 |
setupBottomLayout(act,bottomLayout,2*mObjectSize,mObjectSize);
|
|
245 |
setupBottomLayout(act,bottomLayout,2*mObjectSize); |
|
259 | 246 |
|
260 | 247 |
mObjectPopup = new PopupWindow(act); |
261 | 248 |
mObjectPopup.setFocusable(true); |
... | ... | |
273 | 260 |
colSpecs[col] = GridLayout.spec(col); |
274 | 261 |
} |
275 | 262 |
|
276 |
for(int object = 0; object< NUM_OBJECTS; object++) |
|
263 |
int numObjects = RubikObjectList.getNumObjects(); |
|
264 |
|
|
265 |
for(int object=0; object<numObjects; object++) |
|
277 | 266 |
{ |
278 |
final ObjectType type = ObjectType.getObject(object);
|
|
267 |
final RubikObject robject = RubikObjectList.getObject(object);
|
|
279 | 268 |
int iconSize = RubikActivity.getDrawableSize(); |
280 |
int icons = type.getIconID(iconSize);
|
|
269 |
int icons = robject==null ? 0 : robject.getIconID(iconSize);
|
|
281 | 270 |
int row = object/NUM_COLUMNS; |
282 | 271 |
|
283 | 272 |
ImageButton button = new ImageButton(act); |
... | ... | |
289 | 278 |
{ |
290 | 279 |
if( act.getControl().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY ) |
291 | 280 |
{ |
292 |
mObject = type;
|
|
293 |
act.changeObject(type, true);
|
|
281 |
mObject = robject==null ? 0 : robject.getOrdinal();
|
|
282 |
act.changeObject(mObject, true);
|
|
294 | 283 |
if( mPlayLayout!=null ) adjustLevels(act); |
295 | 284 |
mMovesController.clearMoves(act); |
296 | 285 |
} |
... | ... | |
313 | 302 |
|
314 | 303 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
315 | 304 |
|
316 |
private void setupBottomLayout(final RubikActivity act, final LinearLayout layout, int width, int height)
|
|
305 |
private void setupBottomLayout(final RubikActivity act, final LinearLayout layout, int width) |
|
317 | 306 |
{ |
318 | 307 |
int iconD = RubikActivity.getDrawable(R.drawable.ui_small_info,R.drawable.ui_medium_info, R.drawable.ui_big_info, R.drawable.ui_huge_info); |
319 | 308 |
int iconT = RubikActivity.getDrawable(R.drawable.ui_small_tutorial,R.drawable.ui_medium_tutorial, R.drawable.ui_big_tutorial, R.drawable.ui_huge_tutorial); |
... | ... | |
419 | 408 |
switch(button) |
420 | 409 |
{ |
421 | 410 |
case 0: Bundle sBundle = new Bundle(); |
422 |
sBundle.putInt("tab", mObject.ordinal() );
|
|
411 |
sBundle.putInt("tab", mObject ); |
|
423 | 412 |
sBundle.putBoolean("submitting", false); |
424 | 413 |
RubikDialogScores scores = new RubikDialogScores(); |
425 | 414 |
scores.setArguments(sBundle); |
... | ... | |
471 | 460 |
@Override |
472 | 461 |
public void onClick(View v) |
473 | 462 |
{ |
474 |
RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
|
475 |
int numScrambles = play.getObject().getNumScramble();
|
|
463 |
RubikObject object = RubikObjectList.getObject(mObject);
|
|
464 |
int numScrambles = object==null ? 0 : object.getNumScramble();
|
|
476 | 465 |
mShouldReactToEndOfScrambling = false; |
477 | 466 |
act.getControl().scrambleObject(numScrambles); |
478 | 467 |
} |
... | ... | |
483 | 472 |
|
484 | 473 |
public void savePreferences(SharedPreferences.Editor editor) |
485 | 474 |
{ |
486 |
editor.putString("statePlay_objName", mObject.name() ); |
|
475 |
RubikObject object = RubikObjectList.getObject(mObject); |
|
476 |
|
|
477 |
if( object!=null ) |
|
478 |
{ |
|
479 |
editor.putString("statePlay_objName", object.getName() ); |
|
480 |
} |
|
487 | 481 |
|
488 | 482 |
if( mObjectPopup!=null ) |
489 | 483 |
{ |
... | ... | |
508 | 502 |
|
509 | 503 |
public void restorePreferences(SharedPreferences preferences) |
510 | 504 |
{ |
511 |
String objName= preferences.getString("statePlay_objName", DEF_OBJECT.name() ); |
|
512 |
int ordinal = ObjectType.getOrdinal(objName); |
|
513 |
mObject = ordinal>=0 && ordinal<NUM_OBJECTS ? ObjectType.values()[ordinal] : DEF_OBJECT; |
|
505 |
RubikObject object = RubikObjectList.getObject(DEF_OBJECT); |
|
506 |
String defName = object==null ? "CUBE_3" : object.getName(); |
|
507 |
String objName= preferences.getString("statePlay_objName",defName); |
|
508 |
mObject = RubikObjectList.getOrdinal(objName); |
|
509 |
|
|
510 |
if( mObject<0 || mObject>=RubikObjectList.getNumObjects() ) mObject = DEF_OBJECT; |
|
514 | 511 |
} |
515 | 512 |
|
516 | 513 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
517 | 514 |
|
518 |
public boolean setObject(RubikActivity act, ObjectType obj)
|
|
515 |
public boolean setObject(RubikActivity act, int ordinal)
|
|
519 | 516 |
{ |
520 |
if( mObject!=obj )
|
|
517 |
if( mObject!=ordinal )
|
|
521 | 518 |
{ |
522 |
mObject = obj;
|
|
519 |
mObject = ordinal;
|
|
523 | 520 |
if( mPlayLayout!=null ) adjustLevels(act); |
524 | 521 |
return true; |
525 | 522 |
} |
... | ... | |
576 | 573 |
|
577 | 574 |
public void adjustSolvedIcons() |
578 | 575 |
{ |
579 |
int dbLevel = getDBLevel(mObject); |
|
580 |
int numLevel = Math.min(dbLevel, LEVELS_SHOWN);
|
|
576 |
int dbLevel = RubikObjectList.getDBLevel(mObject);
|
|
577 |
int numLevel= Math.min(dbLevel, LEVELS_SHOWN); |
|
581 | 578 |
RubikScores scores = RubikScores.getInstance(); |
582 | 579 |
|
583 | 580 |
for(int i=0; i<numLevel; i++) |
584 | 581 |
{ |
585 | 582 |
int level = i<numLevel-1 ? i+1 : dbLevel; |
586 | 583 |
Button button = (Button)mPlayLayout.getChildAt(i); |
587 |
int icon = scores.isSolved(mObject.ordinal(), level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
|
584 |
int icon = scores.isSolved(mObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved; |
|
588 | 585 |
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0); |
589 | 586 |
} |
590 | 587 |
} |
... | ... | |
593 | 590 |
|
594 | 591 |
private void adjustLevels(final RubikActivity act) |
595 | 592 |
{ |
596 |
int dbLevel = getDBLevel(mObject); |
|
597 |
int numScrambles = mObject.getNumScramble(); |
|
593 |
int dbLevel = RubikObjectList.getDBLevel(mObject); |
|
594 |
RubikObject object = RubikObjectList.getObject(mObject); |
|
595 |
int numScrambles = object==null ? 0 : object.getNumScramble(); |
|
598 | 596 |
int numLevel = Math.min(dbLevel, LEVELS_SHOWN); |
599 | 597 |
String[] levels = new String[numLevel]; |
600 | 598 |
|
... | ... | |
641 | 639 |
button.setText(levels[i]); |
642 | 640 |
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize); |
643 | 641 |
|
644 |
int icon = scores.isSolved(mObject.ordinal(), level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
|
642 |
int icon = scores.isSolved(mObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved; |
|
645 | 643 |
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0); |
646 | 644 |
|
647 | 645 |
button.setOnClickListener( new View.OnClickListener() |
... | ... | |
665 | 663 |
} |
666 | 664 |
} |
667 | 665 |
|
668 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
669 |
// historically older versions of the app had lower 'maxScrambles' in case of several objects and |
|
670 |
// those got remembered in the server-side DB already, so we need to keep using them. This function |
|
671 |
// provides a map between 'maxScramble' of an object and its 'dbLevel'. All new objects will have |
|
672 |
// those two values the same. |
|
673 |
|
|
674 |
public static int getDBLevel(ObjectType object) |
|
675 |
{ |
|
676 |
switch(object) |
|
677 |
{ |
|
678 |
case CUBE_3: return 16; |
|
679 |
case CUBE_4: return 20; |
|
680 |
case CUBE_5: return 24; |
|
681 |
case PYRA_4: return 15; |
|
682 |
case PYRA_5: return 20; |
|
683 |
case MEGA_5: return 35; |
|
684 |
case DIAM_2: return 10; |
|
685 |
case DIAM_3: return 18; |
|
686 |
case REDI_3: return 14; |
|
687 |
case HELI_3: return 18; |
|
688 |
case SKEW_3: return 17; |
|
689 |
case REX_3 : return 16; |
|
690 |
case MIRR_3: return 16; |
|
691 |
default : return object.getNumScramble(); |
|
692 |
} |
|
693 |
} |
|
694 |
|
|
695 | 666 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
696 | 667 |
|
697 | 668 |
public int getLevel() |
... | ... | |
708 | 679 |
|
709 | 680 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
710 | 681 |
|
711 |
public ObjectType getObject()
|
|
682 |
public int getObject()
|
|
712 | 683 |
{ |
713 | 684 |
return mObject; |
714 | 685 |
} |
Also available in: Unified diff
In the 'magic' app, ObjectType is now only used in RubikObject and RubikObjectList classes and nowhere else.
This is a major step towards being able to download objects from an online repository.